
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <link rel="canonical" href="https://blog.csdn.net/weixin_46211269/article/details/120076709"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="report" content='{"pid": "blog", "spm":"1001.2101"}'>
    <meta name="referrer" content="always">
    <meta http-equiv="Cache-Control" content="no-siteapp" /><link rel="alternate" media="handheld" href="#" />
    <meta name="shenma-site-verification" content="5a59773ab8077d4a62bf469ab966a63b_1497598848">
    <meta name="applicable-device" content="pc">
    <link  href="https://g.csdnimg.cn/static/logo/favicon32.ico"  rel="shortcut icon" type="image/x-icon" />
    <title>❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）_python菜鸟-CSDN博客</title>
    <script>
      (function(){ 
        var el = document.createElement("script"); 
        el.src = "https://s3a.pstatp.com/toutiao/push.js?1abfa13dfe74d72d41d83c86d240de427e7cac50c51ead53b2e79d40c7952a23ed7716d05b4a0f683a653eab3e214672511de2457e74e99286eb2c33f4428830"; 
        el.id = "ttzz"; 
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(el, s);
      })(window)
    </script>
        <meta name="keywords" content="❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）">
        <meta name="csdn-baidu-search"  content='{"autorun":true,"install":true,"keyword":"❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）"}'>
    <meta name="description" content="文章目录强烈推荐系列教程，建议学起来！！一.pycharm下载安装二.python下载安装三.pycharm上配置python四.配置镜像源让你下载嗖嗖的快4.1pycharm内部配置4.2手动添加镜像源4.3永久配置镜像源五.插件安装（比如汉化？）5.1自动补码神器第一款5.2汉化pycharm5.3其它插件六.美女背景七.自定义脚本开头八、这个前言一定要看九、python入门十、python缩进十一、Python注释1.单行注释2.多行注释十二、Python 变量1.变量定义理解2. 变量名命名3. 分">
    <script src="//g.csdnimg.cn/tingyun/1.8.5/blog.js" type='text/javascript'></script>
        <link rel="stylesheet" type="text/css" href="https://csdnimg.cn/release/blogv2/dist/pc/css/detail_enter-049c37bb43.min.css">
    <style>
        #content_views pre{
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none; 
            user-select: none; 
        }
        #content_views pre code{
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none; 
            user-select: none; 
        }
    </style>
    <script type="application/ld+json">{"@context":"https://ziyuan.baidu.com/contexts/cambrian.jsonld","@id":"https://blog.csdn.net/weixin_46211269/article/details/120076709","appid":"1638831770136827","pubDate":"2021-09-03T10:42:36","title":"❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）_python菜鸟-CSDN博客","upDate":"2021-09-03T14:51:30"}</script>
        <link rel="stylesheet" type="text/css" href="https://csdnimg.cn/release/blogv2/dist/pc/themesSkin/skin-years/skin-years-e37b0148f7.min.css">
    <script src="https://csdnimg.cn/public/common/libs/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var isCorporate = false;//注释删除enterprise
        var username =  "weixin_46211269";
        var skinImg = "white";
        var blog_address = "https://chuanchuan.blog.csdn.net";
        var currentUserName = "";
        var isOwner = false;
        var loginUrl = "http://passport.csdn.net/account/login?from=https://blog.csdn.net/weixin_46211269/article/details/120076709";
        var blogUrl = "https://blog.csdn.net/";
        var avatar = "https://profile.csdnimg.cn/9/1/6/3_weixin_46211269";
        var articleTitle = "❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）";
        var articleDesc = "文章目录强烈推荐系列教程，建议学起来！！一.pycharm下载安装二.python下载安装三.pycharm上配置python四.配置镜像源让你下载嗖嗖的快4.1pycharm内部配置4.2手动添加镜像源4.3永久配置镜像源五.插件安装（比如汉化？）5.1自动补码神器第一款5.2汉化pycharm5.3其它插件六.美女背景七.自定义脚本开头八、这个前言一定要看九、python入门十、python缩进十一、Python注释1.单行注释2.多行注释十二、Python 变量1.变量定义理解2. 变量名命名3. 分";
        var articleTitles = "❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）_python菜鸟-CSDN博客";
        var nickName = "川川菜鸟";
        var articleDetailUrl = "https://chuanchuan.blog.csdn.net/article/details/120076709";
        if(window.location.host.split('.').length == 3) {
            blog_address = blogUrl + username;
        }
        var skinStatus = "Black";
        var blogStaticHost = "https://csdnimg.cn/release/blogv2/"
    </script>
        <meta name="toolbar" content='{"type":"1"}'>
        <script>
            window.csdn = window.csdn ? window.csdn : {};
            window.csdn.toolbarIsBlack = true;
            window.csdn.sideToolbar = {
                options: {
                    theme : "black"
                }
            }
        </script>
    <script src="https://g.csdnimg.cn/??fixed-sidebar/1.1.6/fixed-sidebar.js" type="text/javascript"></script>
    <script src='//g.csdnimg.cn/common/csdn-report/report.js' type='text/javascript'></script>
    <link rel="stylesheet" type="text/css" href="https://csdnimg.cn/public/sandalstrap/1.4/css/sandalstrap.min.css">
    <style>
        .MathJax, .MathJax_Message, .MathJax_Preview{
            display: none
        }
    </style>
    <script src="https://dup.baidustatic.com/js/ds.js"></script>
</head>
<body class="nodata " style="">
        <script>
            var toolbarSearchExt = '{"landingWord":[],"queryWord":"","tag":["python","pycharm"],"title":"❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）"}';
        </script>
    <script src="https://g.csdnimg.cn/common/csdn-toolbar/csdn-toolbar.js" type="text/javascript"></script>
    <script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
    </script>
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/pc/css/blog_code-01256533b5.min.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/chart-3456820cac.css" />
<div class="main_father clearfix d-flex justify-content-center" style="height:100%;"> 
    <div class="container clearfix" id="mainBox">
        <main>
<script type="text/javascript">
    function getQueryString(name) {   
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象  
      var r = window.location.search.substr(1).match(reg);  //匹配目标参数
      if( r != null ) return decodeURIComponent( r[2] ); return '';   
    }
    function stripscript(s){ 
      var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？%]") 
      var rs = ""; 
      for (var i = 0; i < s.length; i++) { 
        rs = rs+s.substr(i, 1).replace(pattern, ''); 
      } 
      return rs; 
    }
    var blogHotWords = stripscript(getQueryString('utm_term')).length > 1 ? stripscript(getQueryString('utm_term')) : ''
</script>
<div class="blog-content-box">
        <div class="article-header-box">
        <div class="article-header">
            <div class="article-title-box">
                <h1 class="title-article" id="articleContentId">❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）</h1>
            </div>
            <div class="article-info-box">
                <div class="article-bar-top">
                    <img class="article-type-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/original.png" alt="">
                    <div class="bar-content">
                        <span class="c-gray">置顶</span>
                    <a class="follow-nickName vip-name" href="https://chuanchuan.blog.csdn.net" target="_blank" rel="noopener">川川菜鸟</a>
                    <span class="time">2021-09-03 14:51:30</span>
                    <img class="article-read-img article-heard-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/articleReadEyes.png" alt="">
                    <span class="read-count">56605</span>
                    <a id="blog_detail_zk_collection" class="un-collection" data-report-click='{"mod":"popu_823","spm":"1001.2101.3001.4232","ab":"new"}'>
                        <img class="article-collect-img article-heard-img un-collect-status isdefault" style="display:inline-block" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollect.png" alt="">
                        <img class="article-collect-img article-heard-img collect-status isactive" style="display:none" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollectionActive.png" alt="">
                        <span class="name">收藏</span>
                        <span class="get-collection">
                            5690
                        </span>
                    </a>
                    </div>
                </div>
                <div class="blog-tags-box">
                    <div class="tags-box artic-tag-box">
                            <span class="label">分类专栏：</span>
                                <a class="tag-link" href="https://blog.csdn.net/weixin_46211269/category_11313211.html" target="_blank" rel="noopener">python全栈基础教程系列</a>
                            <span class="label">文章标签：</span>
                                <a data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"python","ab":"new"}' class="tag-link" href="https://www.csdn.net/tags/MtjaQg4sNDk0LWJsb2cO0O0O.html" target="_blank" rel="noopener">python</a>
                                <a data-report-click='{"mod":"popu_626","spm":"1001.2101.3001.4223","strategy":"pycharm","ab":"new"}' class="tag-link" href="https://www.csdn.net/tags/MtTaEg0sMTM2OTUtYmxvZwO0O0OO0O0O.html" target="_blank" rel="noopener">pycharm</a>
                            <a class="origin-plan-box" data-report-click='{"spm":"1001.2101.3001.5794"}' href="https://marketing.csdn.net/p/55d59e00e66e4d3796149b096ae7c810" target="_blank">
                                <img src="https://csdnimg.cn/release/blogv2/dist/components/img/originPlan.png" alt=""><span class="origin-plan-name">原力计划</span>
                            </a>
                    </div>
                </div>
                <div class="slide-content-box">
                    <div class="article-copyright">
                        <div class="creativecommons">
                            版权声明：本文为博主原创文章，遵循<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener"> CC 4.0 BY-NC-SA </a>版权协议，转载请附上原文出处链接和本声明。
                        </div>
                        <div class="article-source-link">
                            本文链接：<a href="https://blog.csdn.net/weixin_46211269/article/details/120076709" target="_blank">https://blog.csdn.net/weixin_46211269/article/details/120076709</a>
                        </div>
                    </div>
                </div>
                <div class="operating">
                    <a class="href-article-edit slide-toggle">版权</a>
                </div>
            </div>
        </div>
    </div>
        <div id="blogColumnPayAdvert">
            <div class="column-group">
                <div class="column-group-item column-group0 column-group-item-one">
                    <div class="item-l">
                        <a class="item-target" href="https://blog.csdn.net/weixin_46211269/category_11313211.html" target="_blank" title="python全栈基础教程系列"
                        data-report-view='{"spm":"1001.2101.3001.6332"}'
                        data-report-click='{"spm":"1001.2101.3001.6332"}'>
                            <img class="item-target" src="https://img-blog.csdnimg.cn/20210825184045537.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224" alt="">
                            <span class="title item-target">python全栈基础教程系列</span>
                        </a>
                        <span class="dec">专栏收录该内容</span>
                    </div>
                    <div class="item-m">
                        <span>28 篇文章</span>
                        <span>341 订阅</span>
                    </div>
                    <div class="item-r">
                            <a class="item-target article-column-bt articleColumnFreeBt" data-id="11313211">订阅专栏</a>
                    </div>
                </div>
            </div>
        </div>
    <article class="baidu_pl">
        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-1a85854398.css">
                <div id="content_views" class="markdown_views prism-tomorrow-night">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <p></p>
<div class="toc">
 <h3>文章目录</h3>
 <ul><li><ul><li><a href="#_2">强烈推荐系列教程&#xff0c;建议学起来&#xff01;&#xff01;</a></li></ul>
  </li><li><a href="#pycharm_12">一.pycharm下载安装</a></li><li><a href="#python_34">二.python下载安装</a></li><li><a href="#pycharmpython_54">三.pycharm上配置python</a></li><li><a href="#_71">四.配置镜像源让你下载嗖嗖的快</a></li><li><ul><li><ul><li><a href="#41pycharm_82">4.1pycharm内部配置</a></li></ul>
   </li><li><a href="#42_109">4.2手动添加镜像源</a></li><li><ul><li><a href="#43_128">4.3永久配置镜像源</a></li></ul>
  </li></ul>
  </li><li><a href="#_148">五.插件安装&#xff08;比如汉化&#xff1f;&#xff09;</a></li><li><ul><li><ul><li><a href="#51_155">5.1自动补码神器第一款</a></li><li><a href="#52pycharm_167">5.2汉化pycharm</a></li><li><a href="#53_184">5.3其它插件</a></li></ul>
  </li></ul>
  </li><li><a href="#_186">六.美女背景</a></li><li><a href="#_192">七.自定义脚本开头</a></li><li><a href="#_199">八、这个前言一定要看</a></li><li><a href="#python_207">九、python入门</a></li><li><a href="#python_226">十、python缩进</a></li><li><a href="#Python_240">十一、Python注释</a></li><li><ul><li><a href="#1_244">1.单行注释</a></li><li><a href="#2_263">2.多行注释</a></li></ul>
  </li><li><a href="#Python__289">十二、Python 变量</a></li><li><ul><li><a href="#1_291">1.变量定义理解</a></li><li><a href="#2__356">2. 变量名命名</a></li><li><a href="#3__396">3. 分配多个值</a></li><li><a href="#4__436">4. 输出变量</a></li><li><a href="#5__490">5. 全局变量与局部变量&#xff0c;全局关键字</a></li><li><a href="#6__537">6. 练习题</a></li></ul>
  </li><li><a href="#Python_544">十三、Python数据类型</a></li><li><ul><li><a href="#1_547">1.置数据类型</a></li><li><a href="#2_563">2.获取数据类型</a></li><li><a href="#3_576">3.设置数据类型</a></li><li><a href="#4_675">4.设置特定数据类型</a></li><li><a href="#6_766">6.练习题</a></li></ul>
  </li><li><a href="#python_819">十四、python数字</a></li><li><ul><li><a href="#1_855">1.整数</a></li><li><a href="#2_869">2.浮点数</a></li><li><a href="#3_896">3.虚数</a></li><li><a href="#4_910">4.类型转换</a></li><li><a href="#5_938">5.随机数</a></li><li><a href="#6_948">6.练习题</a></li></ul>
  </li><li><a href="#python_971">十五、python指定变量类型</a></li><li><a href="#Python_1006">十六、Python字符串</a></li><li><ul><li><a href="#_1008">一.字符串基本使用</a></li><li><ul><li><a href="#1_1010">1.字符串理解</a></li><li><a href="#2_1019">2.将字符串分配给变量</a></li><li><a href="#3_1026">3.多行字符串</a></li><li><a href="#4_1048">4.字符串是数组</a></li><li><a href="#5_1058">5.遍历字符串</a></li><li><a href="#6_1067">6.字符串长度</a></li><li><a href="#7_1076">7.检查字符串</a></li><li><a href="#8_1095">8.检查如果不是</a></li></ul>
   </li><li><a href="#_1116">二.切片字符串</a></li><li><ul><li><a href="#1_1118">1.切片</a></li><li><a href="#2_1132">2.从头开始切片</a></li><li><a href="#3_1144">3.切到最后</a></li><li><a href="#4_1157">4.负索引</a></li></ul>
   </li><li><a href="#_1170">三.修改字符串</a></li><li><ul><li><a href="#1_1173">1.小写转大写</a></li><li><a href="#2_1185">2.大写转小写</a></li><li><a href="#3_1197">3.删除空格</a></li><li><a href="#4_1210">4.替换字符串</a></li><li><a href="#5_1222">5.拆分字符串</a></li></ul>
   </li><li><a href="#_1235">四.字符串连接</a></li><li><a href="#_1261">五.格式化字符串</a></li><li><ul><li><a href="#1format_1263">1.format单个传参</a></li><li><a href="#2format_1286">2.format多个个传参</a></li></ul>
   </li><li><a href="#__1313">六. 字符串的其它处理方法总结</a></li><li><a href="#_1327">七.练习题</a></li></ul>
  </li><li><a href="#Python_1390">十七、Python布尔值</a></li><li><ul><li><ul><li><a href="#1_1396">1.比较</a></li><li><a href="#2_1423">2.评估值和变量</a></li><li><a href="#3_1448">3.布尔真值</a></li><li><a href="#4_1459">4.布尔假值</a></li><li><a href="#5_1476">5.函数可以返回布尔值</a></li><li><a href="#6_1510">6.练习题</a></li></ul>
  </li></ul>
  </li><li><a href="#python_1539">十八、python运算符</a></li><li><ul><li><a href="#1_1542">1.算术运算符</a></li><li><a href="#2_1589">2.赋值运算符</a></li></ul>
  </li><li><a href="#Python_1657">十九、Python列表</a></li><li><ul><li><a href="#_1659">一.列表基本知识</a></li><li><ul><li><a href="#1_1667">1.创建列表</a></li><li><a href="#2_1693">2.列出表值</a></li><li><a href="#3_1717">3.列表长度</a></li><li><a href="#4___1729">4.列表项 - 数据类型</a></li><li><a href="#5Python__1743">5.Python 集合&#xff08;数组&#xff09;</a></li></ul>
   </li><li><a href="#_1751">二.访问列表</a></li><li><ul><li><a href="#1_1753">1.正常索引</a></li><li><a href="#2_1764">2.负索引</a></li><li><a href="#3_1773">3.索引范围</a></li><li><a href="#4_1780">4.负指数范围</a></li><li><a href="#5_1787">5.检查是否存在</a></li></ul>
   </li><li><a href="#_1798">三.更改列表</a></li><li><ul><li><a href="#1_1800">1.单个更改</a></li><li><a href="#2_1813">2.多个更改</a></li><li><a href="#3_1826">3.插入列表</a></li></ul>
   </li><li><a href="#_1839">四.添加列表</a></li><li><ul><li><a href="#1_1841">1.末尾添加</a></li><li><a href="#2_1854">2.指定位置添加</a></li><li><a href="#3_1865">3.合并列表</a></li></ul>
   </li><li><a href="#_1890">五.删除列表</a></li><li><ul><li><a href="#1_1894">1.删除指定目标</a></li><li><a href="#2_1907">2.删除指定索引</a></li><li><a href="#3del_1930">3.del删除指定的索引</a></li><li><a href="#4_1947">4.清除列表</a></li></ul>
   </li><li><a href="#_1962">六.循环列表</a></li><li><ul><li><a href="#1for_1964">1.for循环遍历</a></li><li><a href="#2while_1988">2.while循环遍历</a></li></ul>
   </li><li><a href="#_2001">七.列表推导式</a></li><li><a href="#_2050">八.列表排序</a></li><li><ul><li><a href="#1_2052">1.区分大小写的排序</a></li><li><a href="#2_2065">2.不区分大小写的排序</a></li><li><a href="#3_2078">3.倒序</a></li></ul>
   </li><li><a href="#_2091">九.复制列表</a></li><li><a href="#_2114">十.加入列表</a></li><li><a href="#_2154">十一.列表所有操作总结</a></li><li><a href="#_2159">十二.练习</a></li></ul>
  </li><li><a href="#Python_2217">二十、Python元组</a></li><li><ul><li><a href="#_2221">一.元组理解</a></li><li><ul><li><a href="#11_2223">1.1基本定义</a></li><li><a href="#12_2249">1.2元组长度</a></li><li><a href="#13_2273">1.3数据类型</a></li></ul>
   </li><li><a href="#_2297">二.访问元组</a></li><li><ul><li><a href="#21_2299">2.1正常访问</a></li><li><a href="#22_2311">2.2负索引</a></li><li><a href="#23_2321">2.3范围性索引</a></li></ul>
   </li><li><a href="#_2367">三.更新元组</a></li><li><ul><li><a href="#31_2373">3.1替换</a></li><li><a href="#32_2388">3.2添加项目值</a></li><li><a href="#33_2418">3.3删除项目</a></li></ul>
   </li><li><a href="#_2444">四.解包元组</a></li><li><a href="#_2490">五.循环元祖</a></li><li><ul><li><a href="#51_2492">5.1遍历元祖</a></li><li><a href="#52_While__2516">5.2使用 While 循环</a></li></ul>
   </li><li><a href="#_2526">六.元组合并</a></li><li><a href="#_2569">七.练习</a></li></ul>
  </li><li><a href="#Python_2601">二十一、Python集合</a></li><li><ul><li><a href="#_2603">一.集合理解</a></li><li><a href="#_2623">二.访问集合</a></li><li><ul><li><a href="#21_2626">2.1遍历集合</a></li><li><a href="#32_2640">3.2检查是否存在</a></li></ul>
   </li><li><a href="#_2652">三.添加集合</a></li><li><ul><li><a href="#31_2654">3.1添加项目值</a></li><li><a href="#32_2670">3.2添加集合</a></li><li><a href="#33_2686">3.3添加任何可迭代对象</a></li></ul>
   </li><li><a href="#_2701">四.移除集合项</a></li><li><ul><li><a href="#41remove_2703">4.1remove方法</a></li><li><a href="#42discard__2718">4.2discard() 方法</a></li><li><a href="#43pop__2732">4.3pop() 方法</a></li><li><a href="#44clear__2746">4.4clear() 方法</a></li><li><a href="#45del_2758">4.5del关键字</a></li></ul>
   </li><li><a href="#_2769">五.循环集合</a></li><li><a href="#_2782">六.集合连接</a></li><li><ul><li><a href="#61_2784">6.1普通连接</a></li><li><a href="#62_2809">6.2仅保留重复项</a></li><li><a href="#63_2835">6.3保留所有&#xff0c;但不保留重复项</a></li></ul>
   </li><li><a href="#_2860">七.练习</a></li></ul>
  </li><li><a href="#Python_2899">二十二、Python字典</a></li><li><ul><li><a href="#_2901">一.字典理解</a></li><li><ul><li><a href="#11_2915">1.1创建字典与访问</a></li><li><a href="#12_2945">1.2字典长度</a></li><li><a href="#13_2959">1.3数据类型</a></li></ul>
   </li><li><a href="#_2988">二.访问字典</a></li><li><ul><li><a href="#21_2992">2.1访问键名</a></li><li><a href="#22_3023">2.2访问健值</a></li></ul>
   </li><li><a href="#_3089">三.更改字典各种方法</a></li><li><a href="#_3122">四.添加字典项各种方法</a></li><li><a href="#_3155">五.删除字典的各种方法</a></li><li><a href="#_3226">六.遍历字典</a></li><li><a href="#_3296">七.复制字典</a></li><li><a href="#_3325">八.嵌套字典</a></li><li><a href="#_3376">九.练习</a></li></ul>
  </li><li><a href="#If__Else_3434">二十三、If ... Else语句</a></li><li><ul><li><a href="#if_3445">一.if语句</a></li><li><a href="#_3459">二.缩进</a></li><li><a href="#elif_3471">三.elif语句</a></li><li><a href="#else_3492">四.else语句</a></li><li><ul><li><a href="#41else_3493">4.1基本else</a></li><li><a href="#42and_3523">4.2and语句</a></li><li><a href="#43or__3532">4.3or 语句</a></li><li><a href="#44if_3541">4.4嵌套if语句</a></li><li><a href="#44pass_3552">4.4pass语句</a></li></ul>
  </li></ul>
  </li><li><a href="#while_3562">二十四、while循环语句</a></li><li><ul><li><a href="#_3563">一.基本理解</a></li><li><a href="#_3576">二.中断声明</a></li><li><a href="#continue__3591">三.continue 声明</a></li><li><a href="#else__3604">四.else 语句</a></li></ul>
  </li><li><a href="#for_3618">二十五、for循环语句</a></li><li><ul><li><a href="#_3619">一.基本遍历</a></li><li><a href="#_3628">二.遍历字符串</a></li><li><a href="#_3635">三.中断声明</a></li><li><a href="#continue__3658">四.continue 声明</a></li><li><a href="#range__3670">五.range() 函数</a></li><li><a href="#_3681">六.嵌套循环</a></li><li><a href="#pass_3694">七.pass语句</a></li></ul>
  </li><li><a href="#_3701">二十六、函数</a></li><li><ul><li><a href="#_3704">一.创建函数与调用</a></li><li><a href="#_3721">二.参数</a></li><li><a href="#_3736">三.参数数量</a></li><li><a href="#args_3749">四.任意参数&#xff0c;*args</a></li><li><a href="#_3763">五.关键字参数</a></li><li><a href="#kwargs_3776">七.任意关键字参数&#xff0c;**kwargs</a></li><li><a href="#_3787">八.默认参数值</a></li><li><a href="#_3800">九将列表作为参数传递</a></li><li><a href="#_3812">十.返回值</a></li><li><a href="#pass_3823">十一.pass语句</a></li></ul>
  </li><li><a href="#lambda_3830">二十七、lambda</a></li><li><a href="#_3888">二十八、数组</a></li><li><ul><li><a href="#_3896">一.访问数组的元素</a></li><li><a href="#_3913">二.数组的长度</a></li><li><a href="#_3923">三.修改数组</a></li><li><a href="#_3965">四.数组的其它操作</a></li></ul>
  </li><li><a href="#Python_3967">二十九、Python类和对象</a></li><li><ul><li><a href="#_3971">一.创建类</a></li><li><a href="#_3981">二.创建对象</a></li><li><a href="#__init____3993">三.__init__() 函数</a></li><li><a href="#_4012">四.对象方法</a></li><li><a href="#_4030">五.自参数</a></li><li><a href="#_4047">六.对象及其属性更改</a></li><li><a href="#pass_4098">七.pass语句</a></li></ul>
  </li><li><a href="#Python_4105">三十、Python继承</a></li><li><ul><li><a href="#_4111">一.创建父类</a></li><li><a href="#_4130">二.创建子类</a></li><li><a href="#___init____4160">三.添加 __init__() 函数</a></li><li><a href="#_super__4190">四.使用 super() 函数</a></li><li><a href="#_4213">五.添加属性</a></li><li><a href="#_4257">六.添加方法</a></li></ul>
  </li><li><a href="#Python_4282">三十一、Python日期</a></li><li><ul><li><a href="#_4286">一.日期输入输出</a></li><li><a href="#_4313">二.创建日期对象</a></li><li><a href="#strftime__4328">三.strftime() 方法</a></li><li><a href="#_4339">四.其它调用方法</a></li></ul>
  </li><li><a href="#Python_JSON_4345">三十二、Python JSON</a></li><li><ul><li><a href="#_JSON__Python_4352">一.从 JSON 转换为 Python</a></li></ul>
  </li><li><a href="#_4387">三十三、异常处理</a></li><li><ul><li><a href="#_4392">一.异常处理</a></li><li><a href="#else_4404">二.else搭配</a></li><li><a href="#finally_4417">三.finally语句</a></li><li><a href="#_4444">四.引发异常</a></li></ul>
  </li><li><a href="#_4467">三十四、用户输入</a></li><li><a href="#_4479">三十五.格式化输入输出</a></li><li><a href="#python_4611">三十六、python正则表达式</a></li><li><ul><li><a href="#Python_4619">一.Python中的正则表达式</a></li><li><a href="#_4637">二.正则表达式函数</a></li><li><ul><li><a href="#21_findall__4638">2.1 findall() 函数</a></li><li><a href="#22search__4669">2.2search() 函数</a></li><li><a href="#23_split__4694">2.3 split() 函数</a></li><li><a href="#24_sub__4721">2.4 sub() 函数</a></li></ul>
   </li><li><a href="#_4746">三.元字符</a></li><li><ul><li><a href="#31__4749">3.1 列表符号</a></li><li><a href="#32_4764">3.2转义符</a></li><li><a href="#34__4781">3.4 任意符号</a></li><li><a href="#35_4796">3.5开始符</a></li><li><a href="#36__4813">3.6 结束符</a></li><li><a href="#37__4831">3.7 星号符</a></li><li><a href="#38__4852">3.8 加号符</a></li><li><a href="#39_4875">3.9集合符号</a></li><li><a href="#310_4896">3.10或符</a></li></ul>
   </li><li><a href="#_4917">四.特殊序列</a></li><li><ul><li><a href="#41__4920">4.1 指定字符</a></li><li><a href="#42__4941">4.2 指定开头结尾</a></li><li><a href="#43_4979">4.3匹配中间字符</a></li><li><a href="#44_5022">4.4匹配数字</a></li><li><a href="#45__5044">4.5 匹配非数字</a></li><li><a href="#46__5066">4.6 空格匹配</a></li><li><a href="#47__5088">4.7 匹配非空格</a></li><li><a href="#48__5109">4.8 匹配任意数字和字母</a></li><li><a href="#49_5130">4.9匹配任意非数字和字母</a></li><li><a href="#410__5152">4.10 匹配结尾</a></li></ul>
   </li><li><a href="#_5171">五.集合套装</a></li><li><ul><li><a href="#51__5172">5.1 指定符范围匹配</a></li><li><a href="#52__5189">5.2 匹配任意范围内小写字母</a></li><li><a href="#53__5209">5.3 其它</a></li></ul>
   </li><li><a href="#_5243">六.匹配对象</a></li><li><ul><li><a href="#61_span_5269">6.1 span函数</a></li><li><a href="#62_string_5283">6.2 string函数</a></li><li><a href="#63_group_5295">6.3 group函数</a></li></ul>
  </li></ul>
  </li><li><a href="#_5310">三十七、参考资料</a></li><li><a href="#_5322">三十八、总结</a></li></ul>
</div>
<br /> 
<img src="https://img-blog.csdnimg.cn/abd0d05d0e5a4ecba4d6e53d8ff97a5e.jpg" alt="在这里插入图片描述" />
<p></p> 
<h2><a id="_2"></a>强烈推荐系列教程&#xff0c;建议学起来&#xff01;&#xff01;</h2> 
<p><a href="https://chuanchuan.blog.csdn.net/article/details/119852902">十万字python基础教程&#xff0c;学不会主页联系找我&#xff01;</a></p> 
<p><a href="https://blog.csdn.net/weixin_46211269/category_10912318.html">qq机器人制作系列讲解专栏</a><br /> <a href="https://space.bilibili.com/591228087">qq机器人b站视频教程</a></p> 
<p><a href="https://chuanchuan.blog.csdn.net/article/details/119814777">三万字SQL数据库小白到精通系列</a></p> 
<p><a href="https://blog.csdn.net/weixin_46211269/category_11242184.html">数学建模小白到精通系列</a></p> 
<h1><a id="pycharm_12"></a>一.pycharm下载安装</h1> 
<p>pycharm下载地址&#xff1a;<br /> <code>http://www.jetbrains.com/pycharm/download/#section&#61;windows</code><br /> 下载详细步骤&#xff1a;<br /> 1-<br /> <img src="https://img-blog.csdnimg.cn/b9fb1c63aee6482b91232623edca12c2.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_53,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 2-<br /> <img src="https://img-blog.csdnimg.cn/61bfe722b0264761bd3eacdc06f48324.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_41,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 3-<br /> <img src="https://img-blog.csdnimg.cn/bbf0b0fa978b40f4966781491ddfe747.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_38,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 4-<br /> <img src="https://img-blog.csdnimg.cn/eee267ee82494a269df43acd1811fe3e.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_34,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 5-<br /> <img src="https://img-blog.csdnimg.cn/536e67c2d3584b309fc9437fa939b961.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_39,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 6<br /> <img src="https://img-blog.csdnimg.cn/788e88c9c2a34cc487c74d3fda095478.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_19,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 7-<br /> <img src="https://img-blog.csdnimg.cn/6196065a78e24099b7912042d6903134.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 8-直接finish<br /> <img src="https://img-blog.csdnimg.cn/23e8e8c10b1e4a0fa316cf704c26d4d4.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_31,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/5bbafaaf87544f679497237aea8238af.png" alt="在这里插入图片描述" /></p> 
<h1><a id="python_34"></a>二.python下载安装</h1> 
<p>9-python官网&#xff1a;</p> 
<pre><code>https://www.python.org/
</code></pre> 
<p>进去网址后点击&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/efe3e80d244449df8c03b155dbad59b5.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_40,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 10<br /> <img src="https://img-blog.csdnimg.cn/d1cfaca1f2dd41f1844a8a10b4dd2282.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_42,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 11-下载好后<br /> <img src="https://img-blog.csdnimg.cn/2900c9f423704e5eb59f6261012847b0.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_38,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 12-添加环境变量<br /> <img src="https://img-blog.csdnimg.cn/a9f91ddc0cd74abbb63c9f3bddd261cc.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_41,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/77b81ae092a6424fb9387cae12ffe150.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_29,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/bc799ca9e8644285ad4343ae27e713ba.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_28,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/8afa4975ffa5425581a6eb4095c16ecd.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_31,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/832d5124a75c4c8b94476bfcf94522c0.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_28,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 记得双击安装&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/0700430218f049ad853cde0f0d1bb34b.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_37,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h1><a id="pycharmpython_54"></a>三.pycharm上配置python</h1> 
<p>13-双击桌面pycharm</p> 
<p><img src="https://img-blog.csdnimg.cn/3277d996662a4aa5900b4a185c7b2db3.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_35,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 随便取个名字&#xff08;我取的学习&#xff09;&#xff0c;直接点击create.<br /> 遇到如下情况&#xff0c;则点击ok(没遇到就算了)<br /> <img src="https://img-blog.csdnimg.cn/5a671f835f794cb8ba0bbc6becb44271.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_33,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 14-添加解释器<br /> <img src="https://img-blog.csdnimg.cn/1297fb97e8854bc8a532637309740518.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_47,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/58d73547b8184f4bbd4baba25165a58a.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_40,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/9ae6ffdd6b5d4d98a68500d1d2a825b6.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_41,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/5bed742d838141f3bc4006871da5b589.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/190aff408b35442f862381db88f509c2.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_38,color_FFFFFF,t_70,g_se,x_16" alt="![在这里插入图片描述](https://img-blog.csdnimg.cn/4f4c5fc9f8b64ecebbf4c1046e876036.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" /><br /> 成功如下&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/449e764716054b2f855622155e43e30c.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 打印成功&#xff1a;标志配置完成<br /> <img src="https://img-blog.csdnimg.cn/4c9fe6deccaf41bc98aa32b8ed5893ef.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_40,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h1><a id="_71"></a>四.配置镜像源让你下载嗖嗖的快</h1> 
<p><img src="https://img-blog.csdnimg.cn/1c71334b7755488a9550bceb4bdf05bc.png" alt="在这里插入图片描述" /></p> 
<p>我喜欢用清华的&#xff0c;所以我在这里介绍都用清华源&#xff0c;当然这里是一些比较好用的镜像源&#xff1a;</p> 
<pre><code class="prism language-c">清华&#xff1a;https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
阿里云&#xff1a;http<span class="token operator">:</span><span class="token comment">//mirrors.aliyun.com/pypi/simple/</span>
中国科技大学 https<span class="token operator">:</span><span class="token comment">//pypi.mirrors.ustc.edu.cn/simple/</span>
</code></pre> 
<p>一共有三种镜像源配置&#xff0c;建议你每一种都跟我一起学会。</p> 
<h3><a id="41pycharm_82"></a>4.1pycharm内部配置</h3> 
<p>第一步&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/602abee494d24f468f990d2302c302bb.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 第二步&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/35b4f83c6c2d42488a7acd31c80795ff.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 第三步&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/51315de64d1b4adbaa61d685edef0b5b.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/a6d60c5b1fc24c28bf92d02288862a3d.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 第四步&#xff1a;<br /> 复制上面的清华镜像源粘贴&#xff0c;然后okokokok<br /> <img src="https://img-blog.csdnimg.cn/b25a46107cf14264b89e328714efd7d5.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 测试&#xff0c;遇到了这个问题&#xff1a;<br /> pip : 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写&#xff0c;如果包括路径&#xff0c;请确保路径正确&#xff0c;然后再试一次。<br /> <img src="https://img-blog.csdnimg.cn/ddcfdfef13e04d118dfbcee993073933.png" alt="在这里插入图片描述" /><br /> 因为我忘记给pip加环境变量了&#xff0c;所以加一下&#xff0c;一次如下&#xff1a;</p> 
<p><img src="https://img-blog.csdnimg.cn/440e8911122d415b97cc4425515e5dab.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/e4a2b83794514989ab5d7a55b73331e9.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/917877850bdf4bbda845fc3a4654131d.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/f38ecf25b3d5423cba3807c1860b1b1d.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/cdc83ea514fc41398ab786de3f1e32d1.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 第五步&#xff1a;<br /> 退出pycharm,因为加了环境变量需要重启软件。我们先到cmd输入pip,如下就是配置成功了&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7192975c7d984522a08776dd5fabf300.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 第六步&#xff1a;<br /> 重启软件后&#xff0c;随便装一个模块&#xff0c;如下&#xff1a;&#xff08;你可以看到下载模块速度很快&#xff01;&#xff09;<br /> <img src="https://img-blog.csdnimg.cn/445a4f6e53044e3bbbd0d78f81fa4fad.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h2><a id="42_109"></a>4.2手动添加镜像源</h2> 
<p>使用方法&#xff1a;</p> 
<pre><code class="prism language-c">pip install 下载的模块名 <span class="token operator">-</span>i https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
</code></pre> 
<p>比如我要下载numpy这个模块&#xff0c;执行以下命令&#xff1a;</p> 
<pre><code class="prism language-c">pip install numpy <span class="token operator">-</span>i https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
</code></pre> 
<p>几秒就好了&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4263e85e32444c38b7e6a0ce76f5f410.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 这个方法的好处就是&#xff0c;你不用像其它配置一样要去配置一遍&#xff0c;你只需要在后面加上&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token operator">-</span>i https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
</code></pre> 
<h3><a id="43_128"></a>4.3永久配置镜像源</h3> 
<p>这个配置我是建议你一定要添加配置。<br /> <strong>方法一&#xff1a;</strong><br /> 到cmd执行如下命令创建pip.ini:</p> 
<pre><code class="prism language-c">pip config set global<span class="token punctuation">.</span>index<span class="token operator">-</span>url https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/36109144db0b466695e064fe8de57734.png" alt="在这里插入图片描述" /></p> 
<p>然后我们把这个路径添加到系统环境变量就好了&#xff08;怎么添加环境变量&#xff1f;跟前面给pip添加环境变量一样操作&#xff0c;只是路径不一样&#xff09;</p> 
<p><strong>方法二&#xff1a;</strong><br /> 如果刚刚这个命令你执行失败&#xff0c;你可以自己在c盘创建一个文件名叫做pip&#xff0c;pip文件夹下创建一个文件名pip.ini,内容为&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token punctuation">[</span>global<span class="token punctuation">]</span>
index<span class="token operator">-</span>url <span class="token operator">&#61;</span> https<span class="token operator">:</span><span class="token comment">//pypi.tuna.tsinghua.edu.cn/simple</span>
</code></pre> 
<p>还是一样添加到环境变量。</p> 
<h1><a id="_148"></a>五.插件安装&#xff08;比如汉化&#xff1f;&#xff09;</h1> 
<p><img src="https://img-blog.csdnimg.cn/fd58bce2d47540c0b422e0bc94e7ee9f.png" alt="在这里插入图片描述" /></p> 
<p>首先个人不建议汉化&#xff0c;最后我再演示汉化插件。我是想要推荐一些不错的插件。<br /> 首先进入如下界面&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/96587fadd3f84e7a8aa2bdf3dc16f336.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h3><a id="51_155"></a>5.1自动补码神器第一款</h3> 
<p>推荐使用&#xff1a;TabNine&#xff0c;当然kite也不错&#xff0c;你可以都安装&#xff0c;我是都在用。我演示一款&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/be3d641d502343059f4e3dfdb59a872f.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p><img src="https://img-blog.csdnimg.cn/88e07cfb59534d97a99aeb7747f17207.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/0b672e7816d6473096a532b72397ea3c.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/f2037bea69fd485e9bf7453c5d71bb03.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/8211e5bc4b3c4b2bb4d009afcb8b0e91.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 弹出这个页面删了不要管&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/bd1466d92f9645d1b6a93f092d47b0d5.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> 测试&#xff1a;已经开始有提示了<br /> <img src="https://img-blog.csdnimg.cn/68267655a6da44a8b31e078e3a77b513.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h3><a id="52pycharm_167"></a>5.2汉化pycharm</h3> 
<p>首先&#xff0c;个人不建议汉化&#xff0c;不管你英语好不好&#xff0c;都要去适应这个英语界面&#xff0c;当然你实在需要汉化&#xff0c;这是教程&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/1b72b83fab1745929950644cce80d8c9.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p><img src="https://img-blog.csdnimg.cn/1fbc5d757db549cea4371308090cd989.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p><img src="https://img-blog.csdnimg.cn/20c3caff7521466ea8d47189b8cebd63.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/05c14d5214334174a185e11c165160d6.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p>现在就已经全部汉化&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/380d5aff59444edfb7ec3ebc0f964715.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p><img src="https://img-blog.csdnimg.cn/0a038d80fe7f4e9e90f9a7bdd000e943.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h3><a id="53_184"></a>5.3其它插件</h3> 
<p>如果需要下载别的插件&#xff0c;你可以百度搜一下pycharm有哪些好的插件&#xff0c;都是安装上述方式安装。</p> 
<h1><a id="_186"></a>六.美女背景</h1> 
<p>你是否想要如下桌面&#xff1f;<br /> <img src="https://img-blog.csdnimg.cn/9a13bbd0dec84b34b615588f47ebe8e0.png?x-oss-process&#61;image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p>教程传送门&#xff1a;<br /> <a href="https://chuanchuan.blog.csdn.net/article/details/119854359">美女桌面背景设置</a></p> 
<h1><a id="_192"></a>七.自定义脚本开头</h1> 
<p>你是都在先每次创建一个文件&#xff0c;开头都是如下&#xff1f;<br /> <img src="https://img-blog.csdnimg.cn/fcd6f158ff184c61804896c7760a7897.png" alt="在这里插入图片描述" /><br /> 教程传送门&#xff1a;<br /> <a href="https://chuanchuan.blog.csdn.net/article/details/119833979">自定义脚本开头</a></p> 
<h1><a id="_199"></a>八、这个前言一定要看</h1> 
<p><strong>拥有本篇文章&#xff0c;意味着你拥有一本最完善的书籍</strong>&#xff0c;讲得比书上全&#xff0c;语法也会比买的书上更详细&#xff0c;大家要慢慢看。拥有本篇文章&#xff0c;你将基础无敌&#xff0c;从此可以有能力自学一些高级教程。作者写了好几天&#xff0c;实在很累&#xff0c;<strong>希望你三连支持。</strong></p> 
<p>python&#xff0c;言简意赅就是&#xff1a;通俗易懂&#xff0c;功能强大无比&#xff0c;上手快&#xff0c;实用强。你跟着我在这里认真学完这一篇&#xff0c;你一定会学会最扎实的python基础&#xff0c;同时我还可以提供<strong>免费辅导</strong>&#xff0c;作者本是一名学生&#xff0c;并不图有任何好处。如果需要辅导&#xff0c;可以加从左侧栏加群&#xff0c;当然仅是交流&#xff0c;不会有时间一直教你&#xff0c;只能帮助你解决一些问题&#xff0c;更多要靠自己。<br /> <img src="https://img-blog.csdnimg.cn/607e6fc8969f4e96b3e61acbd46897d8.png" alt="在这里插入图片描述" /></p> 
<h1><a id="python_207"></a>九、python入门</h1> 
<p>软件安装我就不介绍了&#xff0c;大家b站搜一下python和pycharm安装安装即可&#xff0c;个人是推荐<strong>python和pycharm</strong>结合使用&#xff0c;pycharm是什么&#xff1f;是python的编译器&#xff0c;如果我们没有编译器&#xff0c;写代码是很困难的&#xff0c;而且pycharm提供了许多插件和优美的界面&#xff0c;使得你写代码又快又舒服&#xff0c;不会因为在python的IDE上写得头疼。<br /> 当然!下载软件不用到官网下&#xff0c;你只需要到软件管家下载即可&#xff0c;我也是这个公众号的忠实粉丝了。<br /> 入门第一步&#xff1a;打印</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello, World!&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>当然&#xff0c;你想打印别的也可以&#xff0c;对吧&#xff1f;</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;川川帅哥&#xff0c;我爱你&#39;</span><span class="token punctuation">)</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/89c86045dac6409cb57620dc648dc88d.png" alt="在这里插入图片描述" /></p> 
<h1><a id="python_226"></a>十、python缩进</h1> 
<p>最基本的语法&#xff0c;我不可能在这里把所有的语法都讲一遍&#xff0c;但是最基本语法要说一下。在这里&#xff0c;我们又不得不鸣谢<strong>pycharm编译器</strong>&#xff0c;实在帮助我们太多了。为什么这么说&#xff1f;pycharm中&#xff0c;它会自动帮助我们完成换行&#xff0c;缩进等问题&#xff0c;不会像IDE中写代码&#xff0c;要自己手动&#xff0c;如果忘记手动就回报错&#xff0c;因此我是不建议只用python解释器&#xff0c;一定要用pycharm!</p> 
<p>举一些例子,当然&#xff0c;如果你是小白&#xff0c;现在只会打印&#xff0c;大可不必着急&#xff0c;你只需要看看&#xff0c;后面我会讲到。<br /> 比如缩进问题&#xff0c;缩进是指代码行开头的空格。if后面的语句需要tap一下&#xff08;当然&#xff0c;如果你用pycharm编译器&#xff0c;会自动tap&#xff09;。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token keyword">if</span> <span class="token number">6</span> <span class="token operator">&gt;</span> <span class="token number">2</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;六大于二&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/4b90c579bc6c428896827e676f5303f4.png" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_240"></a>十一、Python注释</h1> 
<p>注释可用于解释 Python 代码。注释可用于使代码更具可读性。注释可用于在测试代码时阻止执行。</p> 
<h2><a id="1_244"></a>1.单行注释</h2> 
<p>将需要注释的部分开头用#<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">#川川真帅
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;川川帅哥&#xff0c;我爱你&#39;</span><span class="token punctuation">)</span>
</code></pre> 
<p>或者这样&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello, World!&#34;</span><span class="token punctuation">)</span> #川川真帅
</code></pre> 
<p>你可以看到如下&#xff0c;这就是注释意义了&#xff0c;懂了吧。<br /> <img src="https://img-blog.csdnimg.cn/e5f8c9a845c14f3bbef03859529f3e49.png" alt="在这里插入图片描述" /></p> 
<h2><a id="2_263"></a>2.多行注释</h2> 
<p>第一种方法&#xff08;不建议&#xff0c;太麻烦&#xff09;</p> 
<pre><code class="prism language-c">#川川真帅
#川川真帅
#川川真帅
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello, World!&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>你也可以左键选中我们需要注释的代码&#xff0c;松开&#xff0c;按&#xff1a;Ctrl&#43;/&#xff0c;就完成相同效果注释。<br /> 第二种方法&#xff1a;<br /> 把要注释的内容放到三个引号对里面。&#xff0c;例如&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token string">&#39;&#39;</span>&#39;
川川真帅
川川真帅
<span class="token string">&#39;&#39;</span>&#39;
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;川川帅哥&#xff0c;我爱你&#39;</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>取消注释</strong><br /> 左键选中我们需要取消注释的代码&#xff0c;松开&#xff0c;按&#xff1a;Ctrl&#43;/</p> 
<h1><a id="Python__289"></a>十二、Python 变量</h1> 
<h2><a id="1_291"></a>1.变量定义理解</h2> 
<p>在 Python 中&#xff0c;当你给它赋值时就会创建变量&#xff1a;Python 没有用于声明变量的命令。变量在您第一次为其赋值时创建。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
y <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
</code></pre> 
<p>对于同一个变量&#xff0c;赋值类型不同则会发生类型的变化&#xff0c;例如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">4</span>       # x 现在是整形
x <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span> # x 现在是字符串
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>则打印为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/21d9fd8f068344ea8867a93e86f4f83e.png" alt="在这里插入图片描述" /><br /> 如果要指定变量的数据类型&#xff0c;可以通过强制转换来完成&#xff0c;比如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>    # x will be <span class="token string">&#39;3&#39;</span>
y <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>    # y will be <span class="token number">3</span>
z <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>  # z will be <span class="token number">3.0</span>
</code></pre> 
<p>那么刚刚我说到了类型&#xff0c;小白肯定还不知道类型是什么&#xff0c;怎么查看,我们来说一下如何获取类型&#xff0c;这里我们要用到type函数&#xff0c;举个例子&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
y <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>看看返回什么&#xff1a;int为整形&#xff0c;str为字符串。这是你要背的。<br /> <img src="https://img-blog.csdnimg.cn/0da912231f874f33b152c19f89dc9273.png" alt="在这里插入图片描述" /><br /> 可以使用单引号或双引号来声明字符串变量&#xff1a;</p> 
<pre><code class="prism language-c">x1 <span class="token operator">&#61;</span> <span class="token string">&#34;川川真棒&#34;</span>
x2 <span class="token operator">&#61;</span> <span class="token string">&#39;川川真棒&#39;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x1<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x2<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/5c258abf53294fbb924e70ddfef2f37c.png" alt="在这里插入图片描述" /><br /> 变量名区分大小写&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">4</span>
A <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>A<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;</p> 
<p><img src="https://img-blog.csdnimg.cn/17ac4237b957477ea314df3e6785abec.png" alt="在这里插入图片描述" /></p> 
<h2><a id="2__356"></a>2. 变量名命名</h2> 
<p>变量可以有一个简短的名称&#xff08;如 x 和 y&#xff09;或一个更具描述性的名称&#xff08;age、carname、total_volume&#xff09;。Python 变量的规则&#xff1a;</p> 
<ul><li>变量名必须以字母或下划线字符开头</li><li>变量名不能以数字开头</li><li>变量名称只能包含字母数字字符和下划线&#xff08;Az、0-9 和 _ &#xff09;</li><li>变量名区分大小写&#xff08;age、Age和AGE是三个不同的变量&#xff09;</li></ul> 
<p>例如&#xff1a;</p> 
<pre><code class="prism language-c">myvar <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
my_var <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>&#34;
_my_var <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>&#34;
myVar <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>&#34;
MYVAR <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>&#34;
myvar2 <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>&#34;
</code></pre> 
<p><strong>命名法则&#xff1a;</strong><br /> 骆驼法则&#xff1a;除了第一个单词外&#xff0c;每个单词都以大写字母开头</p> 
<pre><code class="prism language-c">myNameIs <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
</code></pre> 
<p>帕斯卡法则&#xff1a;每个单词都以大写字母开头</p> 
<pre><code class="prism language-c">MyNameIs <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
</code></pre> 
<p>蛇形法则&#xff1a;每个单词由下划线字符分隔</p> 
<pre><code class="prism language-c">My_Name_Is <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
</code></pre> 
<h2><a id="3__396"></a>3. 分配多个值</h2> 
<p><strong>多个变量的多个值。</strong><br /> Python 允许您在一行中为多个变量赋值&#xff1a;</p> 
<pre><code class="prism language-c">x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> z <span class="token operator">&#61;</span> <span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>输出为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/0c32b47f669a4e5ba2ee8594542415cb.png" alt="在这里插入图片描述" /><br /> 注意&#xff1a;确保变量的数量与值的数量相匹配&#xff0c;否则你会得到一个错误。</p> 
<p><strong>多个变量的一个值</strong><br /> 您可以在一行中为多个变量分配相同的值&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> y <span class="token operator">&#61;</span> z <span class="token operator">&#61;</span> <span class="token string">&#34;川川菜鸟&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>输出为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f45ae5f1a9694cda94bc5e72e6447644.png" alt="在这里插入图片描述" /></p> 
<p><strong>打开一个集合</strong><br /> 如果您在列表、元组等中有一组值。Python 允许您将值提取到变量中。这称为拆包。当然&#xff0c;在这里&#xff0c;你可能还不知道集合列表&#xff0c;元组是什么&#xff0c;没有关系&#xff0c;后面我会讲到。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> z <span class="token operator">&#61;</span> fruits
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="4__436"></a>4. 输出变量</h2> 
<p>print语句通常用于输出变量。<br /> 为了组合文本和变量&#xff0c;Python 使用 &#43;字符&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;帅哥是&#34;</span> <span class="token operator">&#43;</span> x<span class="token punctuation">)</span>
</code></pre> 
<p>输出为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/025384ddb5db456d98aa8a692ef826ec.png" alt="在这里插入图片描述" /><br /> 您还可以使用该&#43;字符将一个变量添加到另一个变量中&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;川川真&#34;</span>
y <span class="token operator">&#61;</span> <span class="token string">&#34;帅&#34;</span>
z <span class="token operator">&#61;</span> x <span class="token operator">&#43;</span> y
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>返回一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b09ce74528744ea1b7b34af7280b04e7.png" alt="在这里插入图片描述" /><br /> 对于数字&#xff0c;该&#43;字符用作数学运算符&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">6</span>
y <span class="token operator">&#61;</span> <span class="token number">10</span>
<span class="token function">print</span><span class="token punctuation">(</span>x <span class="token operator">&#43;</span> y<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7dad99dc3657410ebbce452877ab8875.png" alt="在这里插入图片描述" /><br /> 如果你尝试组合一个字符串和一个数字&#xff0c;Python 会给你一个错误&#xff0c;比如&#xff1a;</p> 
<pre><code class="prism language-c">​&#96;&#96;&#96;c
x <span class="token operator">&#61;</span> <span class="token number">5</span>
y <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x <span class="token operator">&#43;</span> y<span class="token punctuation">)</span>
</code></pre> 
<p>该怎么修改呢&#xff1f;把数字转为字符即可&#xff0c;则修改为&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
y <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">str</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">&#43;</span> y<span class="token punctuation">)</span>
</code></pre> 
<p>成功返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4af3fe6874fc42d09a5cce029bf2515b.png" alt="在这里插入图片描述" /></p> 
<h2><a id="5__490"></a>5. 全局变量与局部变量&#xff0c;全局关键字</h2> 
<p>在函数外部创建的变量称为<strong>全局变量</strong>。都可以使用全局变量&#xff0c;无论是在函数内部还是外部。当然&#xff0c;在这里&#xff0c;你可能还不知道函数是什么&#xff0c;后面我会讲到&#xff0c;大可不必慌张。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
def <span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;帅哥是 &#34;</span> <span class="token operator">&#43;</span> x<span class="token punctuation">)</span>
<span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/505a9df327a34676bedbca0b09e826b4.png" alt="在这里插入图片描述" /><br /> 如果在函数内部创建同名变量&#xff0c;该变量将是<strong>局部变量</strong>&#xff0c;只能在函数内部使用。具有相同名称的全局变量将保持原样&#xff0c;全局且具有原始值。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;awesome&#34;</span>

def <span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  x <span class="token operator">&#61;</span> <span class="token string">&#34;fantastic&#34;</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Python is &#34;</span> <span class="token operator">&#43;</span> x<span class="token punctuation">)</span>

<span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Python is &#34;</span> <span class="token operator">&#43;</span> x<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2cb34546817648e4acfd9b48e6187f55.png" alt="在这里插入图片描述" /><br /> <strong>全局关键字</strong><br /> 通常&#xff0c;当您在函数内部创建变量时&#xff0c;该变量是局部的&#xff0c;并且只能在该函数内部使用。要在函数内创建全局变量&#xff0c;可以使用 global关键字。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;帅哥&#34;</span>

def <span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  global x
  x <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟&#34;</span>

<span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span> <span class="token operator">&#43;</span> x<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/0c274d234ff6428cbdaaeb3a124b96ff.png" alt="在这里插入图片描述" /></p> 
<h2><a id="6__537"></a>6. 练习题</h2> 
<ol><li>创建一个名为的变量carname并为其赋值菜鸟。</li><li>创建一个名为的变量x并为其赋值60。</li><li>5 &#43; 10使用两个变量x和y。显示&#xff0c;打印它们的总和</li><li>创建一个名为的变量z&#xff0c;x&#61;8,y&#61;9,分配x &#43; y给它&#xff0c;并显示结果。</li></ol> 
<h1><a id="Python_544"></a>十三、Python数据类型</h1> 
<p><img src="https://img-blog.csdnimg.cn/ac0873254da24e6a935b499fd9c87079.png" alt="在这里插入图片描述" /></p> 
<h2><a id="1_547"></a>1.置数据类型</h2> 
<p>默认情况下&#xff0c;Python 具有以下内置数据类型&#xff0c;在这些类别中&#xff1a;</p> 
<pre><code class="prism language-c">文本类型&#xff1a;	str
数字类型&#xff1a;	<span class="token keyword">int</span><span class="token punctuation">,</span> <span class="token keyword">float</span><span class="token punctuation">,</span> complex
序列类型&#xff1a;	list<span class="token punctuation">,</span> tuple<span class="token punctuation">,</span> range
映射类型&#xff1a;	dict
套装类型&#xff1a;	set<span class="token punctuation">,</span> frozenset
布尔类型&#xff1a;	bool
二进制类型&#xff1a;	bytes<span class="token punctuation">,</span> bytearray<span class="token punctuation">,</span> memoryview
</code></pre> 
<p>此时你大可不必知道这些类型到底是什么&#xff0c;在后续的深入中&#xff0c;你一定会用得到&#xff0c;所以是需要记住的。</p> 
<h2><a id="2_563"></a>2.获取数据类型</h2> 
<p>您可使用以下<strong>type()函数</strong>获取<strong>任何</strong>对象的数据类型。<br /> 例如&#xff0c;打印变量 x 的数据类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">6</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>我们可以看到返回为&#xff1a;int类型<br /> <img src="https://img-blog.csdnimg.cn/39f9b340ecd442a3b59308b36e05fe67.png" alt="在这里插入图片描述" /></p> 
<h2><a id="3_576"></a>3.设置数据类型</h2> 
<p>在 Python 中&#xff0c;数据类型是在为变量赋值时设置的。<br /> 例如以下例子。<br /> str字符串&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span> 
</code></pre> 
<p>int整形&#xff1a;</p> 
<pre><code class="prism language-c">x1 <span class="token operator">&#61;</span> <span class="token number">6</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x1<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>float浮点类型&#xff1a;</p> 
<pre><code class="prism language-c">x2 <span class="token operator">&#61;</span> <span class="token number">6.5</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x2<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>complex复数类型&#xff1a;</p> 
<pre><code class="prism language-c">x3 <span class="token operator">&#61;</span> <span class="token number">2</span>j
<span class="token function">print</span><span class="token punctuation">(</span>x3<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x3<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>list列表类型&#xff1a;</p> 
<pre><code class="prism language-c">x4 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>x4<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x4<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>tuple元祖类型&#xff1a;</p> 
<pre><code class="prism language-c">x5 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x5<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x5<span class="token punctuation">)</span><span class="token punctuation">)</span> 
</code></pre> 
<p>后面还有其它一些类型&#xff0c;我就不以完整代码形式演示了&#xff0c;直接以例子形式让大家看看什么样子是什么类型&#xff0c;当然如果你能亲自动手像我上面的例子一样进行操作打印看一看就再好不过了。<br /> range范围类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">6</span>
</code></pre> 
<p>dict字典类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;age&#34;</span> <span class="token operator">:</span> <span class="token number">36</span><span class="token punctuation">}</span>	
</code></pre> 
<p>set集合类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>
</code></pre> 
<p>不常用的冻结集类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">frozenset</span><span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> 
<p>bool布尔类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> True
</code></pre> 
<p>不常用byte字节类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> b<span class="token string">&#34;Hello&#34;</span>
</code></pre> 
<p>不常用bytearray字节数组类型&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">bytearray</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
</code></pre> 
<p>更有冷门到爆的memoryview内存试图类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">memoryview</span><span class="token punctuation">(</span><span class="token function">bytes</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="4_675"></a>4.设置特定数据类型</h2> 
<p>我会举一些例子说明&#xff0c;尽量很全&#xff0c;大可不必担心。先举一个完整例子&#xff0c;后面的是一样的打印就不演示了。<br /> 强调特定x为字符串&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span><span class="token string">&#34;Hello World&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6d879abacfc845afb87292a790923caa.png" alt="在这里插入图片描述" /><br /> 强调x为整形&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调x为浮点&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token number">20.5</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调x为复数&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">complex</span><span class="token punctuation">(</span><span class="token number">1</span>j<span class="token punctuation">)</span>
</code></pre> 
<p>强调为列表</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调为元祖</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">tuple</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调为范围</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调为字典</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">dict</span><span class="token punctuation">(</span>name<span class="token operator">&#61;</span><span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span> age<span class="token operator">&#61;</span><span class="token number">36</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调为集合</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">set</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调冻结集&#xff08;没啥用的类型&#xff09;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">frozenset</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调布尔类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">bool</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调字节类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">bytes</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调字节组类型</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">bytearray</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
</code></pre> 
<p>强调内存试图类型&#xff08;又是没啥用的类型&#xff09;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token function">memoryview</span><span class="token punctuation">(</span><span class="token function">bytes</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="6_766"></a>6.练习题</h2> 
<p>回答下面的问题结果为什么类型&#xff1f;<br /> 1-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>2-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>3-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">20.5</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>4-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>5-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>6-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;age&#34;</span> <span class="token operator">:</span> <span class="token number">36</span><span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>7-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> True
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h1><a id="python_819"></a>十四、python数字</h1> 
<p><img src="https://img-blog.csdnimg.cn/a2d8f03ac9a94cd0bba45c3e835a90c8.png" alt="在这里插入图片描述" /></p> 
<p>Python 共有三种数字类型&#xff1a;</p> 
<ul><li>int</li><li>float</li><li>complex<br /> 三种类型分别对应如下例子&#xff1a;</li></ul> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">1</span>    # <span class="token keyword">int</span>
y <span class="token operator">&#61;</span> <span class="token number">2.8</span>  # <span class="token keyword">float</span>
z <span class="token operator">&#61;</span> <span class="token number">1</span>j   # complex
</code></pre> 
<p>要验证 Python 中任何对象的类型&#xff0c;请使用以下type()函数&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>因此你可以运行如下代码&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">1</span>    # <span class="token keyword">int</span>
y <span class="token operator">&#61;</span> <span class="token number">2.8</span>  # <span class="token keyword">float</span>
z <span class="token operator">&#61;</span> <span class="token number">1</span>j   # complex
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="1_855"></a>1.整数</h2> 
<p>Int 或 integer&#xff0c;是一个整数&#xff0c;正负&#xff0c;不带小数&#xff0c;长度不限。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">1</span>
y <span class="token operator">&#61;</span> <span class="token number">3562254887</span>
z <span class="token operator">&#61;</span> <span class="token operator">-</span><span class="token number">35522</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="2_869"></a>2.浮点数</h2> 
<p>浮点数或“浮点数”是包含一位或多位小数的正数或负数。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">1.10</span>
y <span class="token operator">&#61;</span> <span class="token number">1.0</span>
z <span class="token operator">&#61;</span> <span class="token operator">-</span><span class="token number">35.59</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>浮点数也可以是带有“e”的科学数字&#xff0c;表示 10 的幂。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">35e3</span>
y <span class="token operator">&#61;</span> <span class="token number">12E4</span>
z <span class="token operator">&#61;</span> <span class="token operator">-</span><span class="token number">87.7e100</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="3_896"></a>3.虚数</h2> 
<p>复数写有“j”作为虚部。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">3</span><span class="token operator">&#43;</span><span class="token number">5</span>j
y <span class="token operator">&#61;</span> <span class="token number">5</span>j
z <span class="token operator">&#61;</span> <span class="token operator">-</span><span class="token number">5</span>j

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="4_910"></a>4.类型转换</h2> 
<p>比如你可以从一种类型转变成另一种同int()&#xff0c; float()和complex()方法。<br /> 例如&#xff1a;&#xff08;你可以亲自运行一下&#xff09;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">1</span>    # <span class="token keyword">int</span>
y <span class="token operator">&#61;</span> <span class="token number">2.8</span>  # <span class="token keyword">float</span>
z <span class="token operator">&#61;</span> <span class="token number">1</span>j   # complex


a <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>


b <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>


c <span class="token operator">&#61;</span> <span class="token function">complex</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="5_938"></a>5.随机数</h2> 
<p>Python 有一个内置模块 random可以用来生成随机数。<br /> 示例&#xff1a;导入 random 模块&#xff0c;并显示 1 到 10之间的一个随机数&#xff1a;</p> 
<pre><code class="prism language-c">import random
<span class="token function">print</span><span class="token punctuation">(</span>random<span class="token punctuation">.</span><span class="token function">randrange</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="6_948"></a>6.练习题</h2> 
<p>1-插入正确的语法将 x 转换为浮点数。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
x <span class="token operator">&#61;</span> <span class="token function">_</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>2-插入正确的语法以将 x 转换为整数。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5.5</span>
x <span class="token operator">&#61;</span> <span class="token function">_</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>3-插入正确的语法以将 x 转换为复数。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
x <span class="token operator">&#61;</span> <span class="token function">_</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<h1><a id="python_971"></a>十五、python指定变量类型</h1> 
<p><img src="https://img-blog.csdnimg.cn/453e78fe05be4bb1b6439e18a46630d0.png" alt="在这里插入图片描述" /></p> 
<p>python 中的转换是使用构造函数完成的&#xff1a;</p> 
<ul><li>int() - 从整数文字、浮点文字&#xff08;通过删除所有小数&#xff09;或字符串文字&#xff08;提供字符串表示整数&#xff09;构造整数</li><li>float() - 从整数文字、浮点文字或字符串文字构造浮点数&#xff08;提供字符串表示浮点数或整数&#xff09;</li><li>str() - 从多种数据类型构造一个字符串&#xff0c;包括字符串、整数文字和浮点文字</li></ul> 
<p>我将每一个类型都举例子说明。<br /> <strong>整数</strong></p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>   # x will be <span class="token number">1</span>
y <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">2.8</span><span class="token punctuation">)</span> # y will be <span class="token number">2</span>
z <span class="token operator">&#61;</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token string">&#34;3&#34;</span><span class="token punctuation">)</span> # z will be <span class="token number">3</span>
</code></pre> 
<p><strong>浮点</strong></p> 
<pre><code class="prism language-c">x2 <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>     # x will be <span class="token number">1.0</span>
y2 <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token number">2.8</span><span class="token punctuation">)</span>   # y will be <span class="token number">2.8</span>
z2 <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token string">&#34;3&#34;</span><span class="token punctuation">)</span>   # z will be <span class="token number">3.0</span>
w2 <span class="token operator">&#61;</span> <span class="token keyword">float</span><span class="token punctuation">(</span><span class="token string">&#34;4.2&#34;</span><span class="token punctuation">)</span> # w will be <span class="token number">4.2</span>
</code></pre> 
<p><strong>字符串</strong></p> 
<pre><code class="prism language-c">x1 <span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span><span class="token string">&#34;s1&#34;</span><span class="token punctuation">)</span> # x will be <span class="token string">&#39;s1&#39;</span>
y1 <span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>    # y will be <span class="token string">&#39;2&#39;</span>
z1 <span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span><span class="token number">3.0</span><span class="token punctuation">)</span>  # z will be <span class="token string">&#39;3.0&#39;</span>
</code></pre> 
<h1><a id="Python_1006"></a>十六、Python字符串</h1> 
<h2><a id="_1008"></a>一.字符串基本使用</h2> 
<h3><a id="1_1010"></a>1.字符串理解</h3> 
<p>python 中的字符串被单引号或双引号包围。&#39;hello’与&#34;hello&#34;相同。您可以使用以下print()函数显示字符串文字&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;Hello&#39;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="2_1019"></a>2.将字符串分配给变量</h3> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="3_1026"></a>3.多行字符串</h3> 
<p>您可以使用三个引号将多行字符串分配给变量&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;&#34;</span>&#34;从前有座山&#xff0c;
山里有座庙
庙里有个小和尚<span class="token string">&#34;&#34;</span>&#34;
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
</code></pre> 
<p>返回如下&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/13e8c413a3da49038f21921334d72ac3.png" alt="在这里插入图片描述" /><br /> 或三个单引号&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#39;&#39;</span>&#39;从前有座山&#xff0c;
山里有座庙
庙里有个小和尚<span class="token string">&#39;&#39;</span>&#39;
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="4_1048"></a>4.字符串是数组</h3> 
<p>Python 没有字符数据类型&#xff0c;单个字符只是一个长度为 1 的字符串。方括号可用于访问字符串的元素。这里用到了切片&#xff0c;你可以不懂。<br /> 获取位置 1 处的字符&#xff08;记住第一个字符的位置为 0&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="5_1058"></a>5.遍历字符串</h3> 
<p>循环遍历单词“chuanchuan”中的字母&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token keyword">for</span> x in <span class="token string">&#34;chuanchuan&#34;</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="6_1067"></a>6.字符串长度</h3> 
<p>len()函数返回字符串的长度&#xff0c;注意标点符号和空格也算一个长度&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="7_1076"></a>7.检查字符串</h3> 
<p>要检查字符串中是否存在某个短语或字符&#xff0c;我们可以使用关键字 in。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;The best things in life are free!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;free&#34;</span> in txt<span class="token punctuation">)</span>
</code></pre> 
<p>返回布尔类型(True代表有)&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/01d225d5655e408f94d853f7a3366b29.png" alt="在这里插入图片描述" /><br /> 也可以通过if来判断是否存在&#xff1a;</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;The best things in life are free!&#34;</span>
<span class="token keyword">if</span> <span class="token string">&#34;free&#34;</span> in txt<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;是的, &#39;free&#39;存在.&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="8_1095"></a>8.检查如果不是</h3> 
<p>检查以下文本中是否不存在“川川”&#xff1a;</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川就读上海交大!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span> not in txt<span class="token punctuation">)</span>
</code></pre> 
<p>因为存在&#xff0c;返回false:<br /> <img src="https://img-blog.csdnimg.cn/d5574c6df0bc4e1597735362cb0a3d8f.png" alt="在这里插入图片描述" /><br /> 仅在不存在“川川”时才打印&#xff1a;</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川就读上海交大!&#34;</span>
<span class="token keyword">if</span> <span class="token string">&#34;川川&#34;</span> not in txt<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;No, &#39;川川&#39; 不在文档.&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>因为不符合条件&#xff0c;所以不会打印。</p> 
<h2><a id="_1116"></a>二.切片字符串</h2> 
<h3><a id="1_1118"></a>1.切片</h3> 
<p>您可以使用切片语法返回一系列字符。指定开始索引和结束索引&#xff0c;以冒号分隔&#xff0c;以返回字符串的一部分。<br /> 示例&#xff1a;获取从位置 2 到位置 5 的字符&#xff08;不包括在内&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">b <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>b<span class="token punctuation">[</span><span class="token number">2</span><span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/796bd4586f6e449ea2e40d4a652359ff.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;第一个字符的索引为 0。</p> 
<h3><a id="2_1132"></a>2.从头开始切片</h3> 
<p>示例&#xff1a;获取从开始到位置 5 的字符&#xff08;不包括在内&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">b <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>b<span class="token punctuation">[</span><span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/add8aa002e6440f1b05f5e8735f09f81.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1144"></a>3.切到最后</h3> 
<p>通过省略结束索引&#xff0c;范围将到最后。<br /> 例如&#xff0c;获取从位置 2 到最后的字符&#xff1a;</p> 
<pre><code class="prism language-c">b <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>b<span class="token punctuation">[</span><span class="token number">2</span><span class="token operator">:</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b625364d9a044bba9ccd46af50f78528.png" alt="在这里插入图片描述" /></p> 
<h3><a id="4_1157"></a>4.负索引</h3> 
<p>使用负索引从字符串末尾开始切片&#xff0c;就是从右往左看&#xff0c;不再是从左往右看。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">b <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>b<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">5</span><span class="token operator">:</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/df85f626d839467d9bafec41774ff048.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1170"></a>三.修改字符串</h2> 
<p><img src="https://img-blog.csdnimg.cn/04461ae3fc3e4aca95737c1a62f53136.png" alt="在这里插入图片描述" /></p> 
<h3><a id="1_1173"></a>1.小写转大写</h3> 
<p>upper()方法以大写形式返回字符串&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">upper</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/df741ab91196485b8f88c40e2fa09b6c.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_1185"></a>2.大写转小写</h3> 
<p>lower()方法以小写形式返回字符串&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">lower</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4ea02a5c095e44ecaeb41a904c21b6c3.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1197"></a>3.删除空格</h3> 
<p>空白是实际文本之前和/或之后的空间&#xff0c;通常您想删除这个空间。<br /> strip()方法从开头或结尾删除任何空格&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34; Hello, World! &#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">strip</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/1117174003da48b983be3827569dc181.png" alt="在这里插入图片描述" /></p> 
<h3><a id="4_1210"></a>4.替换字符串</h3> 
<p>replace()方法用另一个字符串替换一个字符串.</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">&#34;H&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;J&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8bb859b2814845c08e8973f0d35a933c.png" alt="在这里插入图片描述" /></p> 
<h3><a id="5_1222"></a>5.拆分字符串</h3> 
<p>split()方法返回一个列表&#xff0c;其中指定分隔符之间的文本成为列表项。split()如果找到分隔符的实例&#xff0c;该方法会将字符串拆分为子字符串。<br /> 例如我要将下面的字符串以逗号分隔&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello, World!&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&#34;,&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e52130d79f2d4918ad66ec088e6c7729.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1235"></a>四.字符串连接</h2> 
<p>要连接或组合两个字符串&#xff0c;您可以使用 &#43; 运算符。<br /> 例如&#xff0c;将变量a与变量b, 合并到变量中c&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello&#34;</span>
b <span class="token operator">&#61;</span> <span class="token string">&#34;World&#34;</span>
c <span class="token operator">&#61;</span> a <span class="token operator">&#43;</span> b
<span class="token function">print</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b997b12bd9ce49ed9b9b1728b5c5ed78.png" alt="在这里插入图片描述" /><br /> 例如要在a和b变量之间添加空格&#xff0c;请添加&#34; &#34;&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token string">&#34;Hello&#34;</span>
b <span class="token operator">&#61;</span> <span class="token string">&#34;World&#34;</span>
c <span class="token operator">&#61;</span> a <span class="token operator">&#43;</span> <span class="token string">&#34; &#34;</span> <span class="token operator">&#43;</span> b
<span class="token function">print</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/63e1fd0df0dc4ce6b3d3731ca44ee418.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1261"></a>五.格式化字符串</h2> 
<h3><a id="1format_1263"></a>1.format单个传参</h3> 
<p>我们不能像这样组合字符串和数字&#xff1a;</p> 
<pre><code class="prism language-c">#会报错
age <span class="token operator">&#61;</span> <span class="token number">20</span>
txt <span class="token operator">&#61;</span><span class="token string">&#34; 川川今年 &#34;</span> <span class="token operator">&#43;</span> age
<span class="token function">print</span><span class="token punctuation">(</span>txt<span class="token punctuation">)</span>
</code></pre> 
<p>但是我们可以通过使用<strong>format()</strong> 方法来组合字符串和数字&#xff01;format()方法接受传递的参数&#xff0c;格式化它们&#xff0c;并将它们放在占位符所在的字符串中 {}。<br /> 例如&#xff0c;使用format()方法将数字插入字符串:</p> 
<pre><code class="prism language-c">age <span class="token operator">&#61;</span> <span class="token number">20</span>
txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川今年 {}&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>txt<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>age<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7a5d777a49b74ed08e77f68289f7f436.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2format_1286"></a>2.format多个个传参</h3> 
<p>format() 方法接受无限数量的参数&#xff0c;并放置在各自的占位符中&#xff1a;</p> 
<pre><code class="prism language-c">quantity <span class="token operator">&#61;</span> <span class="token number">20</span>
itemno <span class="token operator">&#61;</span> <span class="token number">3000</span>
price <span class="token operator">&#61;</span> <span class="token number">49.95</span>
myorder <span class="token operator">&#61;</span> <span class="token string">&#34;川川今年 {}岁 买了个华为手机 {} 每个月花费 {} 元.&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>myorder<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>quantity<span class="token punctuation">,</span> itemno<span class="token punctuation">,</span> price<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/dbe4564cdacb490fabc03a36a3cdaba4.png" alt="在这里插入图片描述" /><br /> 您可以使用索引号{0}来确保参数放置在正确的占位符中&#xff1a;</p> 
<pre><code class="prism language-c">quantity <span class="token operator">&#61;</span> <span class="token number">20</span>
itemno <span class="token operator">&#61;</span> <span class="token number">3000</span>
price <span class="token operator">&#61;</span> <span class="token number">49.95</span>
myorder <span class="token operator">&#61;</span> <span class="token string">&#34;川川今年 {2}岁 买了个华为手机 {0} 每个月花费 {1} 元.&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>myorder<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>quantity<span class="token punctuation">,</span> itemno<span class="token punctuation">,</span> price<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>这样就会导致数字传的顺序发生了变化&#xff0c;看看结果就明白了&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/949b564a95214be0bb8c7a0a1421ba31.png" alt="在这里插入图片描述" /></p> 
<h2><a id="__1313"></a>六. 字符串的其它处理方法总结</h2> 
<ol><li>capitalize() 将第一个字符转换为大写</li><li>casefold() 将字符串转换为小写</li><li>center() 返回一个居中的字符串</li><li>count() 返回指定值在字符串中出现的次数</li><li>encode() 返回字符串的编码版本</li><li>endswith() 如果字符串以指定的值结尾&#xff0c;则返回 true</li><li>join() 将可迭代的元素连接到字符串的末尾</li><li>find() 在字符串中搜索指定值并返回找到它的位置</li><li>format() 初始化字符串中的指定值<br /> 10.index() 在字符串中搜索指定值并返回找到它的位置<br /> 当然还有很多&#xff0c;个人感觉不是很常用&#xff0c;就不继续总结别的了。</li></ol> 
<h2><a id="_1327"></a>七.练习题</h2> 
<p>1-使用 len 方法打印字符串的长度。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>  <span class="token punctuation">)</span>
</code></pre> 
<p>2-获取字符串 txt 的第一个字符。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
x <span class="token operator">&#61;</span>
</code></pre> 
<p>3.获取从索引 2 到索引 4 (llo) 的字符。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
x <span class="token operator">&#61;</span>
</code></pre> 
<p>4.返回开头或结尾没有任何空格的字符串。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34; Hello World &#34;</span>
x <span class="token operator">&#61;</span> 
</code></pre> 
<p><strong>提示</strong> 使用strip()<br /> 5-将 txt 的值转换为大写。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
txt <span class="token operator">&#61;</span>
</code></pre> 
<p>6-将 txt 的值转换为小写。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
txt <span class="token operator">&#61;</span> 
</code></pre> 
<p>7-用 J 替换字符 H。</p> 
<pre><code class="prism language-c">txt <span class="token operator">&#61;</span> <span class="token string">&#34;Hello World&#34;</span>
txt <span class="token operator">&#61;</span> txt<span class="token punctuation">.</span>
</code></pre> 
<p>8-插入正确的语法以添加年龄参数的占位符。</p> 
<pre><code class="prism language-c">age <span class="token operator">&#61;</span> <span class="token number">36</span>
txt <span class="token operator">&#61;</span> <span class="token string">&#34;My name is John, and I am   &#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>txt<span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>age<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>提示&#xff1a;{}</p> 
<h1><a id="Python_1390"></a>十七、Python布尔值</h1> 
<p><img src="https://img-blog.csdnimg.cn/9164d6737f274706aa0b44f0605198f7.png" alt="在这里插入图片描述" /></p> 
<p>布尔值表示两个值之一&#xff1a; True或False。在编程中&#xff0c;您经常需要知道表达式是否为 True或False。举一些例子就明白了。</p> 
<h3><a id="1_1396"></a>1.比较</h3> 
<p>当您比较两个值时&#xff0c;将计算表达式并且 Python 返回布尔值答案&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&gt;</span> <span class="token number">9</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&#61;&#61;</span> <span class="token number">9</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&lt;</span> <span class="token number">9</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/10e6905db0cf4865836177f013a11f6f.png" alt="在这里插入图片描述" /><br /> 在 if 语句中运行条件时&#xff0c;Python 返回 True or False&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">100</span>
b <span class="token operator">&#61;</span> <span class="token number">30</span>

<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b大于a&#34;</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b不大于a&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8d6c9ae6dea7494a9b24f3ee79c883c8.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_1423"></a>2.评估值和变量</h3> 
<p>bool()函数允许您评估任何值&#xff0c;并给您 True或False 作为返回。<br /> 例如&#xff1a;评估一个字符串和一个数字</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e8c22d36a0d74415b20d90b7f130ed54.png" alt="在这里插入图片描述" /><br /> 评估两个变量&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span>
y <span class="token operator">&#61;</span> <span class="token number">15</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/020bd6ba402e410ca9e453e590b57174.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1448"></a>3.布尔真值</h3> 
<p>True如果它具有某种内容&#xff0c;几乎任何值都会被评估。任何字符串都是True&#xff0c;空字符串除外。任何数字都是True&#xff0c;除了 0。任何列表、元组、集合和字典都是True&#xff0c;空的除外。<br /> 例如以下都会返回True:</p> 
<pre><code class="prism language-c"><span class="token function">bool</span><span class="token punctuation">(</span><span class="token string">&#34;abc&#34;</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="4_1459"></a>4.布尔假值</h3> 
<p>实际上&#xff0c;False除了空值&#xff08;例如()、 []、{}、 “”、 数字 0和 值 &#xff09;之外&#xff0c;计算为 的值 None。当然&#xff0c;结果为 False。</p> 
<pre><code class="prism language-c"><span class="token function">bool</span><span class="token punctuation">(</span>False<span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span>None<span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token string">&#34;&#34;</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token function">bool</span><span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/0a0fbe95c2f34fa09456871993e63bdb.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjIxMTI2OQ&#61;&#61;,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述" /></p> 
<h3><a id="5_1476"></a>5.函数可以返回布尔值</h3> 
<pre><code class="prism language-c">def <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">:</span>
  <span class="token keyword">return</span> True

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/ea1af825753d46148b07233ac728139e.png" alt="在这里插入图片描述" /><br /> 打印“YES&#xff01;” 如果函数返回 True&#xff0c;否则打印“NO&#xff01;”&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">:</span>
  <span class="token keyword">return</span> True

<span class="token keyword">if</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;YES!&#34;</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;NO!&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>Python 也有许多返回布尔值的内置函数&#xff0c;如 isinstance() 函数&#xff0c;可用于确定对象是否属于某种数据类型<br /> 例如&#xff1a;检查对象是否为整数</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">200</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">isinstance</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> <span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为<br /> <img src="https://img-blog.csdnimg.cn/78a0ce68ecde40f3b854533611e740f5.png" alt="在这里插入图片描述" /></p> 
<h3><a id="6_1510"></a>6.练习题</h3> 
<p>1.回答下面的语句返回值True还是False:</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&gt;</span> <span class="token number">9</span><span class="token punctuation">)</span>
</code></pre> 
<p>2.回答下面的语句返回值True还是False:<br /> <code>print(10 &#61;&#61; 9)</code></p> 
<p>3.回答下面的语句返回值True还是False:</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">&lt;</span> <span class="token number">9</span><span class="token punctuation">)</span>
</code></pre> 
<p>4.回答下面的语句返回值True还是False:</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span><span class="token string">&#34;abc&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>5.回答下面的语句返回值True还是False:</p> 
<pre><code class="prism language-c"><span class="token function">print</span><span class="token punctuation">(</span><span class="token function">bool</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h1><a id="python_1539"></a>十八、python运算符</h1> 
<p><img src="https://img-blog.csdnimg.cn/0690636beca740b591586c9bf06a914d.png" alt="在这里插入图片描述" /></p> 
<h2><a id="1_1542"></a>1.算术运算符</h2> 
<p>自己赋值粘贴运行下就懂了&#xff01;<br /> 加减法&#xff1a;&#xff08;&#43; -&#xff09;</p> 
<pre><code class="prism language-c">a<span class="token operator">&#61;</span><span class="token number">2</span>
b<span class="token operator">&#61;</span><span class="token number">3</span>
c<span class="token operator">&#61;</span>a<span class="token operator">-</span>b
d<span class="token operator">&#61;</span>a<span class="token operator">-</span>b
<span class="token function">print</span><span class="token punctuation">(</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span>
</code></pre> 
<p>乘除法&#xff1a;&#xff08;* /&#xff09;</p> 
<pre><code class="prism language-c">a<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token operator">-</span><span class="token number">5</span><span class="token operator">*</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">4</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>

a<span class="token operator">&#61;</span><span class="token number">8</span><span class="token operator">/</span><span class="token number">5</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
</code></pre> 
<p>取余数&#xff08;同时与除法比较&#xff09;</p> 
<pre><code class="prism language-c"><span class="token string">&#39;&#39;</span><span class="token string">&#39;/返回为float,//返回整数&#xff0c;%返回余数&#39;</span><span class="token string">&#39;&#39;</span>
a<span class="token operator">&#61;</span><span class="token number">17</span><span class="token operator">/</span><span class="token number">3</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>


a<span class="token operator">&#61;</span><span class="token number">17</span><span class="token comment">//3</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>

a<span class="token operator">&#61;</span><span class="token number">5</span><span class="token operator">*</span><span class="token number">3</span><span class="token operator">&#43;</span><span class="token number">2</span>
<span class="token function">print</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
</code></pre> 
<p>幂运算 &#xff08;**’&#xff09;</p> 
<pre><code class="prism language-c"><span class="token string">&#39;&#39;</span><span class="token string">&#39;幂运算  **&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span><span class="token number">4</span><span class="token operator">*</span><span class="token operator">*</span><span class="token number">2</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">b</span><span class="token expression"><span class="token operator">&#61;</span><span class="token number">2</span><span class="token operator">*</span><span class="token operator">*</span><span class="token number">3</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span></span></span>
</code></pre> 
<h2><a id="2_1589"></a>2.赋值运算符</h2> 
<p>等于&#xff08;&#61;&#xff09;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>加等于&#xff08; &#43;&#61;&#xff09;等效&#xff1a; x &#61; x &#43;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
x <span class="token operator">&#43;&#61;</span> <span class="token number">3</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>减等于&#xff08;-&#61;&#xff09; 等效&#xff1a;x&#61;x-</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">5</span>
x <span class="token operator">-&#61;</span> <span class="token number">3</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>类似的我们可以得到以下不同的方式等效&#xff1a;</p> 
<pre><code class="prism language-c">	x <span class="token operator">*&#61;</span> <span class="token number">3</span> 等效	x <span class="token operator">&#61;</span> x <span class="token operator">*</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">/&#61;</span> <span class="token number">3</span>等效	x <span class="token operator">&#61;</span> x <span class="token operator">/</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">%&#61;</span> <span class="token number">3</span>	等效 x <span class="token operator">&#61;</span> x <span class="token operator">%</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token comment">//&#61; 3	等效 x &#61; x // 3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">*</span><span class="token operator">*&#61;</span> <span class="token number">3</span>	等效 x <span class="token operator">&#61;</span> x <span class="token operator">*</span><span class="token operator">*</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">&amp;&#61;</span> <span class="token number">3</span>	等效 x <span class="token operator">&#61;</span> x <span class="token operator">&amp;</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">|&#61;</span> <span class="token number">3</span>	等效 x <span class="token operator">&#61;</span> x <span class="token operator">|</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">^&#61;</span> <span class="token number">3</span>	等效 x <span class="token operator">&#61;</span> x <span class="token operator">^</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">&gt;&gt;&#61;</span> <span class="token number">3</span>	等效x <span class="token operator">&#61;</span> x <span class="token operator">&gt;&gt;</span> <span class="token number">3</span>
</code></pre> 
<pre><code class="prism language-c">	x <span class="token operator">&lt;&lt;&#61;</span> <span class="token number">3</span>	等效x <span class="token operator">&#61;</span> x <span class="token operator">&lt;&lt;</span> <span class="token number">3</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/c87d1990dc81405284e86166624f70ca.png" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_1657"></a>十九、Python列表</h1> 
<h2><a id="_1659"></a>一.列表基本知识</h2> 
<p>基本形式为&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
</code></pre> 
<h3><a id="1_1667"></a>1.创建列表</h3> 
<p>列表是使用方括号创建的&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/86f039c8d1304a07810416fc982c888b.png" alt="在这里插入图片描述" /><br /> 创建新列表时也可以使用 <strong>list()</strong> 构造函数。</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thislist<span class="token punctuation">)</span>
</code></pre> 
<p><strong>允许重复</strong><br /> 由于列表已编入索引&#xff0c;因此列表可以包含具有相同值的项目&#xff1a;</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>thislist<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="2_1693"></a>2.列出表值</h3> 
<p>列表项是有序的、可变的&#xff0c;并允许重复值。列表项被索引&#xff0c;第一项有索引[0]&#xff0c;第二项有索引[1]等等。<br /> <strong>单个索引</strong><br /> 例如我要索取川川一号&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/5d03bb804e604b599d7db4079a47fbd3.png" alt="在这里插入图片描述" /><br /> <strong>遍历列表</strong></p> 
<pre><code class="prism language-c"><span class="token keyword">for</span> i in mylist<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/faf565e9d61b474aaeb6d8e5ed4ad4a8.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1717"></a>3.列表长度</h3> 
<p>确定列表有多少项&#xff0c;请使用以下 len()函数&#xff1a;</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>thislist<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/78305e7738924925b4aedeb431101aba.png" alt="在这里插入图片描述" /></p> 
<h3><a id="4___1729"></a>4.列表项 - 数据类型</h3> 
<p>列表项可以是任何数据类型。例如&#xff1a;</p> 
<pre><code class="prism language-c">list1 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
list2 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span>
list3 <span class="token operator">&#61;</span> <span class="token punctuation">[</span>True<span class="token punctuation">,</span> False<span class="token punctuation">,</span> False<span class="token punctuation">]</span>

<span class="token function">print</span><span class="token punctuation">(</span>list1<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>list2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>list3<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="5Python__1743"></a>5.Python 集合&#xff08;数组&#xff09;</h3> 
<ol><li>List列表是一个有序且可变的集合。允许重复成员。</li><li>turple元组是一个有序且不可更改的集合。允许重复成员。</li><li>Set集合是一个无序且无索引的集合。没有重复的成员。</li><li>dict字典是一个有序*且可变的集合。没有重复的成员。<br /> &#xff01;&#xff01;&#xff01;从 Python 3.7 版开始&#xff0c;字典才是有序的&#xff01;&#xff01;&#xff01;</li></ol> 
<h2><a id="_1751"></a>二.访问列表</h2> 
<h3><a id="1_1753"></a>1.正常索引</h3> 
<p>列表项已编入索引&#xff0c;您可以通过引用索引号来访问它们&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>注意</strong>&#xff1a;第一项的索引为 0。</p> 
<h3><a id="2_1764"></a>2.负索引</h3> 
<p>负索引意味着从头开始&#xff0c;-1指最后一项&#xff0c; -2指倒数第二项等。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="3_1773"></a>3.索引范围</h3> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token number">1</span><span class="token operator">:</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="4_1780"></a>4.负指数范围</h3> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">3</span><span class="token operator">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="5_1787"></a>5.检查是否存在</h3> 
<p>要确定列表中是否存在指定的项目&#xff0c;请使用in关键字。<br /> 例如&#xff0c;检查列表中是否存在“apple”&#xff1a;</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">if</span> <span class="token string">&#34;apple&#34;</span> in thislist<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Yes, &#39;apple&#39; is in the fruits list&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_1798"></a>三.更改列表</h2> 
<h3><a id="1_1800"></a>1.单个更改</h3> 
<p>要更改特定位置的值&#xff0c;需要通过索引号&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token string">&#34;川川五号&#34;</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>修改成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9188fe6359444b1fb4a392df390f4ad9.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_1813"></a>2.多个更改</h3> 
<p>索引号需要用范围表示。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川五号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">[</span><span class="token number">1</span><span class="token operator">:</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token punctuation">[</span><span class="token string">&#34;哈皮川川&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;憨批川川&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>修改成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/512d201257134946a22ff82922317815.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1826"></a>3.插入列表</h3> 
<p>insert()方法在指定的索引处插入一个项目。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥呀&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>插入成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/747ce10e28ca45e9bc61366a00722d5c.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1839"></a>四.添加列表</h2> 
<h3><a id="1_1841"></a>1.末尾添加</h3> 
<p>要将值添加到列表的末尾&#xff0c;请使用append() 方法&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&#34;憨批川川&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>添加成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/da75ff86ea104c95a4da5386567fd0a5.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_1854"></a>2.指定位置添加</h3> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>添加成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/74026c5b04064f47abe39f4347295deb.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_1865"></a>3.合并列表</h3> 
<p>要将另一个列表中的元素附加到当前列表&#xff0c;请使用extend()方法。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist1 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">extend</span><span class="token punctuation">(</span>mylist1<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>合并成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f51acb03a7ee42e9af2587e899747ffb.png" alt="在这里插入图片描述" /><br /> extend()方法不一定要 列表&#xff0c;您也可以添加任何可迭代对象&#xff08;元组、集合、字典等&#xff09;。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist2<span class="token operator">&#61;</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
mylist<span class="token punctuation">.</span><span class="token function">extend</span><span class="token punctuation">(</span>mylist2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>添加成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/721175685e5c480897c05c0583dc3be3.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1890"></a>五.删除列表</h2> 
<p><img src="https://img-blog.csdnimg.cn/7928eac263754deba4c760051289664e.png" alt="在这里插入图片描述" /></p> 
<h3><a id="1_1894"></a>1.删除指定目标</h3> 
<p>remove()方法删除指定的项目。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">&#39;川川二号&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>删除成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/281f15338fe34f71856c80ed721e5e83.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_1907"></a>2.删除指定索引</h3> 
<p>pop()方法删除指定的索引。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>删除成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8e08f6f4d2aa4b3c86d410c1779deb87.png" alt="在这里插入图片描述" /><br /> 如果不指定索引&#xff0c;该pop()方法将删除最后一项。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>删除成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/71dffe1b5d674f3bb48eb117447b0b62.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3del_1930"></a>3.del删除指定的索引</h3> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
del mylist<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>删除成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2c594ceea8144c76880b0cc30164816a.png" alt="在这里插入图片描述" /><br /> 该del关键字也可以完全删除列表。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
del mylist
</code></pre> 
<h3><a id="4_1947"></a>4.清除列表</h3> 
<p>clear()方法清空列表。该列表仍然存在&#xff0c;但没有内容。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>清空&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/3bca8e5afaf143dfb42db72706d3245f.png" alt="在这里插入图片描述" /><br /> 坚持&#xff01;&#xff01;&#xff01;<br /> <img src="https://img-blog.csdnimg.cn/cef57edf92c2400b94ab40640e760247.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_1962"></a>六.循环列表</h2> 
<h3><a id="1for_1964"></a>1.for循环遍历</h3> 
<p>方法一&#xff1a;<br /> 循环遍历列表您可以使用循环遍历列表项for 。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> i in mylist<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p>遍历成功&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/48c1f717a4124a419ba43f2c91028d5c.png" alt="在这里插入图片描述" /><br /> 方法二&#xff1a;遍历索引号</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> i in <span class="token function">range</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/40abe080deaa4841b7b5f94908338f89.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2while_1988"></a>2.while循环遍历</h3> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
i <span class="token operator">&#61;</span> <span class="token number">0</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
  i <span class="token operator">&#61;</span> i <span class="token operator">&#43;</span> <span class="token number">1</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7a0d677372c444e095d11fedf122311c.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2001"></a>七.列表推导式</h2> 
<p>例如&#xff1a;根据fruits列表&#xff0c;您需要一个新列表&#xff0c;其中仅包含名称中带有字母“a”的fruits。<br /> 如果没有列表理解&#xff0c;您将不得不编写一个for带有条件测试的语句&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">]</span>
newlist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>

<span class="token keyword">for</span> x in fruits<span class="token operator">:</span>
  <span class="token keyword">if</span> <span class="token string">&#34;a&#34;</span> in x<span class="token operator">:</span>
    newlist<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>newlist<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f58dcc19ccd84912a1b95b231b94fc9a.png" alt="在这里插入图片描述" /></p> 
<p>使用列表推导式&#xff0c;你只需要一行代码即可&#xff01;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">]</span>

newlist <span class="token operator">&#61;</span> <span class="token punctuation">[</span>x <span class="token keyword">for</span> x in fruits <span class="token keyword">if</span> <span class="token string">&#34;a&#34;</span> in x<span class="token punctuation">]</span>

<span class="token function">print</span><span class="token punctuation">(</span>newlist<span class="token punctuation">)</span>
</code></pre> 
<p>返回一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/ad95fa69d91e4a9f92fec12c8b5bd117.png" alt="在这里插入图片描述" /><br /> 换一个例子&#xff0c;只接受小于 5 的数字&#xff1a;</p> 
<pre><code class="prism language-c">newlist <span class="token operator">&#61;</span> <span class="token punctuation">[</span>x <span class="token keyword">for</span> x in <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">if</span> x <span class="token operator">&lt;</span> <span class="token number">5</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>newlist<span class="token punctuation">)</span>
</code></pre> 
<p>返回“orange”而不是“banana”&#xff1a;&#xff08;这个不是很好理解&#xff0c;多想想&#xff09;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">]</span>
newlist <span class="token operator">&#61;</span> <span class="token punctuation">[</span>x <span class="token keyword">if</span> x <span class="token operator">!&#61;</span> <span class="token string">&#34;banana&#34;</span> <span class="token keyword">else</span> <span class="token string">&#34;orange&#34;</span> <span class="token keyword">for</span> x in fruits<span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>newlist<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/97c25f6f18b744f783b56d2f74c30b17.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2050"></a>八.列表排序</h2> 
<h3><a id="1_2052"></a>1.区分大小写的排序</h3> 
<p>默认情况下&#xff0c;该sort()方法区分大小写&#xff0c;导致所有大写字母都排在小写字母之前&#xff1a;</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;Orange&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;Kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
thislist<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thislist<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/da9f81614ee54515800ff59ec0ba66a1.png" alt="在这里插入图片描述" /></p> 
<h3><a id="2_2065"></a>2.不区分大小写的排序</h3> 
<p>如果你想要一个不区分大小写的排序函数&#xff0c;使用 str.lower 作为键函数&#xff1a;</p> 
<pre><code class="prism language-c">thislist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;Orange&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;Kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
thislist<span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span>key <span class="token operator">&#61;</span> str<span class="token punctuation">.</span>lower<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thislist<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/d90cd674f3bc4678a0cc03e917df585c.png" alt="在这里插入图片描述" /></p> 
<h3><a id="3_2078"></a>3.倒序</h3> 
<p>reverse()方法反转元素的当前排序顺序。</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
mylist<span class="token punctuation">.</span><span class="token function">reverse</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/caf7740e4d474abe9e94a8f0658d4f0e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2091"></a>九.复制列表</h2> 
<p>copy()方法制作列表的副本&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
my <span class="token operator">&#61;</span> mylist<span class="token punctuation">.</span><span class="token function">copy</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>my<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/123eb074d9e043bfb48351bd8e3d6858.png" alt="在这里插入图片描述" /><br /> list()方法制作列表的副本&#xff1a;</p> 
<pre><code class="prism language-c">mylist <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#34;川川四号&#34;</span><span class="token punctuation">]</span>
my <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span>mylist<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>my<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7f37cfbc8365432bbb7b2d7d8a291491.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2114"></a>十.加入列表</h2> 
<p>最简单的方法之一是使用&#43; 运算符。</p> 
<pre><code class="prism language-c">list1 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;a&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;b&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;c&#34;</span><span class="token punctuation">]</span>
list2 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span>
list3 <span class="token operator">&#61;</span> list1 <span class="token operator">&#43;</span> list2
<span class="token function">print</span><span class="token punctuation">(</span>list3<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/73d269f72973482e9f178671a1c64d74.png" alt="在这里插入图片描述" /><br /> 稍微有意思点&#xff0c;连接两个列表的另一种方法是将 list2 中的所有项一个一个地附加到 list1 中&#xff1a;</p> 
<pre><code class="prism language-c">list1 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;a&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;b&#34;</span> <span class="token punctuation">,</span> <span class="token string">&#34;c&#34;</span><span class="token punctuation">]</span>
list2 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span>

<span class="token keyword">for</span> x in list2<span class="token operator">:</span>
  list1<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>list1<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2b32a508055e46ae8efbd03716e703a0.png" alt="在这里插入图片描述" /><br /> extend() 方法&#xff0c;其目的是将元素从一个列表添加到另一个列表&#xff1a;</p> 
<pre><code class="prism language-c">list1 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;a&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;b&#34;</span> <span class="token punctuation">,</span> <span class="token string">&#34;c&#34;</span><span class="token punctuation">]</span>
list2 <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span>

list1<span class="token punctuation">.</span><span class="token function">extend</span><span class="token punctuation">(</span>list2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>list1<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/78e718c4dea74bbea0e5fe8dbfa392fd.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2154"></a>十一.列表所有操作总结</h2> 
<p>如果你英文好可以看看&#xff0c;当然&#xff0c;这些所有操作我都讲过一遍了。<br /> <img src="https://img-blog.csdnimg.cn/1712dbfb398b4485ae5c82ed2d389f9b.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjIxMTI2OQ&#61;&#61;,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述" /></p> 
<h2><a id="_2159"></a>十二.练习</h2> 
<p>1-打印fruits列表中的第二项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>
</code></pre> 
<p>2-将fruits列表中的值从“apple”改为“kiwi”。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
   <span class="token operator">&#61;</span>
</code></pre> 
<p>3-使用 append 方法将“orange”添加到fruits列表中。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>

</code></pre> 
<p>4-使用插入方法将“柠檬”添加为fruits列表中的第二项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
     <span class="token operator">&#61;</span><span class="token string">&#34;lemon&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>5-使用 remove 方法从fruits列表中删除“banana”。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>

</code></pre> 
<p>6-使用负索引打印列表中的最后一项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
print&#xff08;  &#xff09;
</code></pre> 
<p>7-使用索引范围打印列表中的第三、第四和第五项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;orange&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;melon&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>fruits<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>8-使用正确的语法打印列表中的项目数</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span> <span class="token punctuation">)</span>
</code></pre> 
<h1><a id="Python_2217"></a>二十、Python元组</h1> 
<p><img src="https://img-blog.csdnimg.cn/c914908a4af2489a960612c33303c1f6.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2221"></a>一.元组理解</h2> 
<h3><a id="11_2223"></a>1.1基本定义</h3> 
<p>元组用于在单个变量中存储多个项目。Tuple 是 Python 中用于存储数据集合的 4 种内置数据类型之一&#xff0c;其他 3 种是List、 Set和Dictionary&#xff0c;它们具有不同的性质和用法。元组是一个集合是有序的和不可改变的。元组是用圆括号写的。<br /> 基本形式如下&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span>
</code></pre> 
<p>元组项是<strong>有序的、不可更改</strong>的&#xff0c;并<strong>允许重复</strong>值。元组项被索引&#xff0c;第一项被索引[0]&#xff0c;第二项被索引[1]等。<br /> 允许<strong>重复</strong>举个例子&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span>
</code></pre> 
<p><strong>索引</strong>举个例子&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">)</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span></span></span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="12_2249"></a>1.2元组长度</h3> 
<p>我们还是跟列表一样&#xff0c;用到len函数&#xff0c;例子如下&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span></span></span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回长度&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/82a74a8c75914de1baf530c4b6c18ae5.png" alt="在这里插入图片描述" /><br /> <strong>一项元组</strong>&#xff0c;记住逗号&#xff0c;不然就不是元祖了&#xff01;我将两个形式读写出来&#xff0c;可以做一个对比&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span><span class="token punctuation">)</span>
mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>我们来看看返回什么&#xff1a;第一个是元祖&#xff0c;第二个是字符串。<br /> <img src="https://img-blog.csdnimg.cn/662350c0fa0b46cb957c24f97ed85808.png" alt="在这里插入图片描述" /></p> 
<h3><a id="13_2273"></a>1.3数据类型</h3> 
<p>元组项可以是任何数据类型&#xff1a;字符串、整数和布尔数据类型.</p> 
<pre><code class="prism language-c">tuple1 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
tuple2 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>
tuple3 <span class="token operator">&#61;</span> <span class="token punctuation">(</span>True<span class="token punctuation">,</span> False<span class="token punctuation">,</span> False<span class="token punctuation">)</span>
</code></pre> 
<p>元组可以包含不同的数据类型。<br /> 包含字符串、整数和布尔值的元组&#xff0c;形式如下&#xff1a;</p> 
<pre><code class="prism language-c">tuple4 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token number">34</span><span class="token punctuation">,</span> True<span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>使用tuple()来创建元组&#xff0c;形式如下&#xff1a;</p> 
<pre><code class="prism language-c">tuple5 <span class="token operator">&#61;</span> <span class="token function">tuple</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>tuple5<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_2297"></a>二.访问元组</h2> 
<h3><a id="21_2299"></a>2.1正常访问</h3> 
<p>您可以通过引用方括号内的索引号来访问元组项&#xff0c;比如打印第二项&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">)</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>mytuple<span class="token punctuation">)</span></span></span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>注意</strong>&#xff1a;第一项的索引为 0。</p> 
<h3><a id="22_2311"></a>2.2负索引</h3> 
<p>负索引意味着从头开始。-1指最后一项&#xff0c; -2指倒数第二项等。<br /> 例如打印元组的最后一项&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="23_2321"></a>2.3范围性索引</h3> 
<p>您可以通过指定范围的开始和结束位置来指定索引范围。指定范围时&#xff0c;返回值将是具有指定项的新元组。这里我们用到range函数&#xff0c;前面讲过。<br /> 返回第三、第四和第五项&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥川川&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川真棒&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token number">2</span><span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>注意</strong>&#xff1a;搜索将从索引 2&#xff08;包括&#xff09;开始并在索引 5&#xff08;不包括&#xff09;处结束。<br /> 请记住&#xff0c;第一项的索引为 0。</p> 
<p>通过<strong>省略起始值</strong>&#xff0c;范围将从第一项开始&#xff08;自己打印看看&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥川川&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川真棒&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token operator">:</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>通过<strong>省略结束值</strong>&#xff0c;范围将继续到列表的末尾&#xff1a;</p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥川川&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川真棒&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token number">2</span><span class="token operator">:</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>负数范围</strong></p> 
<pre><code class="prism language-c">mytuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥川川&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川真棒&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mytuple<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">4</span><span class="token operator">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>检查项目值是否存在</strong><br /> 要确定元组中是否存在指定的项目&#xff0c;请使用in关键字&#xff1a;</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;帅哥川川&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川真棒&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> <span class="token string">&#34;帅哥川川&#34;</span> in thistuple<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;哈哈, &#39;帅哥川川&#39; 在元祖列表&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/ff93b050eb9b46c699323268725a70c6.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2367"></a>三.更新元组</h2> 
<p><img src="https://img-blog.csdnimg.cn/2387dd2d91e14e90b0549a680cf5f8ef.png" alt="在这里插入图片描述" /></p> 
<p>元组是不可更改的&#xff0c;这意味着一旦创建了元组&#xff0c;您就无法更改、添加或删除项目。但是有一些解决方法&#xff1a;将元组转换为列表&#xff0c;更改列表&#xff0c;然后将列表转换回元组。</p> 
<h3><a id="31_2373"></a>3.1替换</h3> 
<p>比如我要将下面第二个元素改为帅哥&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
y <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
y<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">&#61;</span> <span class="token string">&#34;帅哥&#34;</span>
x <span class="token operator">&#61;</span> <span class="token function">tuple</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b9a3d5a5c1084351943ccc5b749ef90e.png" alt="在这里插入图片描述" /></p> 
<h3><a id="32_2388"></a>3.2添加项目值</h3> 
<p>由于元组是不可变的&#xff0c;它们没有内置 append()方法&#xff0c;但有其他方法可以向元组添加项。<br /> <strong>方法1</strong>:转换为列表&#xff1a;就像更改元组的解决方法一样&#xff0c;您可以将其转换为列表&#xff0c;添加您的项目&#xff0c;然后将其转换回元组。<br /> 例如&#xff1a;将元组转换为列表&#xff0c;添加“爱你”&#xff0c;然后将其转换回元组&#xff1a;</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
y <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span>
y<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&#34;爱你&#34;</span><span class="token punctuation">)</span>
thistuple <span class="token operator">&#61;</span> <span class="token function">tuple</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/71f8ec8aecfd4f4ba36aa849524663de.png" alt="在这里插入图片描述" /><br /> 方法2&#xff1a;将元组添加到元组。您可以向元组添加元组&#xff0c;因此如果您想添加一个&#xff08;或多个&#xff09;项目&#xff0c;请使用该项目创建一个新元组&#xff0c;并将其添加到现有元组中。<br /> 例如&#xff1a;创建一个值为“orange”的新元组&#xff0c;并添加该元组</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
y <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;爱你&#34;</span><span class="token punctuation">,</span><span class="token punctuation">)</span>
thistuple <span class="token operator">&#43;&#61;</span> y
<span class="token function">print</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span>
</code></pre> 
<p>同样返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/877e8de13a2542fca3c6a9ab851ede40.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;创建只有一个item的元组时&#xff0c;记得在item后面加上逗号&#xff0c;否则不会被识别为元组。</p> 
<h3><a id="33_2418"></a>3.3删除项目</h3> 
<p>注意&#xff1a;您不能删除元组中的项目。元组是不可更改的&#xff0c;因此您无法从中删除项目&#xff0c;但您可以使用与我们用于更改和添加元组项目相同的解决方法&#xff1a;</p> 
<p>示例<br /> 将元组转换为列表&#xff0c;删除“apple”&#xff0c;然后将其转换回元组&#xff1a;</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
y <span class="token operator">&#61;</span> <span class="token function">list</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span>
y<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">)</span>
thistuple <span class="token operator">&#61;</span> <span class="token function">tuple</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span>
</code></pre> 
<p>或者您可以完全删除元组&#xff1a;该del关键字可以完全删除的元组</p> 
<pre><code class="prism language-c">this <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
del this
<span class="token function">print</span><span class="token punctuation">(</span>this<span class="token punctuation">)</span>
</code></pre> 
<p>这就会返回错误&#xff0c;因为这个元祖已经不在了。<br /> <img src="https://img-blog.csdnimg.cn/6f3eec8913774bd292f91116ed95e577.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2444"></a>四.解包元组</h2> 
<p>当我们创建一个元组时&#xff0c;我们通常会为其分配值。这称为“打包”元组。<br /> 包装元组&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>fruits<span class="token punctuation">)</span>
</code></pre> 
<p>但是&#xff0c;在 Python 中&#xff0c;我们也可以将值提取回变量中。这称为“解包”。<br /> 解包元组&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
<span class="token punctuation">(</span>green<span class="token punctuation">,</span> yellow<span class="token punctuation">,</span> red<span class="token punctuation">)</span> <span class="token operator">&#61;</span> fruits
<span class="token function">print</span><span class="token punctuation">(</span>green<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>yellow<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>red<span class="token punctuation">)</span>
</code></pre> 
<p><strong>使用星号</strong>*<br /> 如果变量的数量少于值的数量&#xff0c;您可以*在变量名中添加一个&#xff0c;值将作为列表分配给变量。<br /> 将其余值分配为名为“red”的列表&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;strawberry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;raspberry&#34;</span><span class="token punctuation">)</span>
<span class="token punctuation">(</span>green<span class="token punctuation">,</span> yellow<span class="token punctuation">,</span> <span class="token operator">*</span>red<span class="token punctuation">)</span> <span class="token operator">&#61;</span> fruits
<span class="token function">print</span><span class="token punctuation">(</span>green<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>yellow<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>red<span class="token punctuation">)</span>
</code></pre> 
<p>如果星号被添加到另一个变量名而不是最后一个&#xff0c;Python 将为变量赋值&#xff0c;直到剩余的值数量与剩余的变量数量匹配。<br /> 添加值列表“tropic”变量&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;papaya&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;pineapple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>

<span class="token punctuation">(</span>green<span class="token punctuation">,</span> <span class="token operator">*</span>tropic<span class="token punctuation">,</span> red<span class="token punctuation">)</span> <span class="token operator">&#61;</span> fruits

<span class="token function">print</span><span class="token punctuation">(</span>green<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>tropic<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>red<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_2490"></a>五.循环元祖</h2> 
<h3><a id="51_2492"></a>5.1遍历元祖</h3> 
<p>也就是遍历元组的意思&#xff0c;只要我们提到遍历&#xff0c;那就是for循环。<br /> <strong>方法一</strong>&#xff1a;直接遍历<br /> 例子如下&#xff1a;遍历项目并打印值</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> i in thistuple<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p><strong>方法二&#xff1a;</strong> 遍历索引号<br /> 使用range()和len()函数创建合适的可迭代对象。</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> i in <span class="token function">range</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回都i为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/06803be67cf748cdba86ecc7b3383061.png" alt="在这里插入图片描述" /></p> 
<h3><a id="52_While__2516"></a>5.2使用 While 循环</h3> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
i <span class="token operator">&#61;</span> <span class="token number">0</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>thistuple<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
  i <span class="token operator">&#61;</span> i <span class="token operator">&#43;</span> <span class="token number">1</span>
</code></pre> 
<h2><a id="_2526"></a>六.元组合并</h2> 
<p>合并两个元祖&#xff0c;我们用&#43;连接即可。</p> 
<pre><code class="prism language-c">tuple1 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
tuple2 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span>

tuple3 <span class="token operator">&#61;</span> tuple1 <span class="token operator">&#43;</span> tuple2
<span class="token function">print</span><span class="token punctuation">(</span>tuple3<span class="token punctuation">)</span>
</code></pre> 
<p>如果要将元组的内容乘以给定次数&#xff0c;可以使用* 运算符&#xff1a;</p> 
<pre><code class="prism language-c">tuple1 <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川一号&#39;</span><span class="token punctuation">)</span>
tuple4<span class="token operator">&#61;</span>tuple1<span class="token operator">*</span><span class="token number">2</span>
<span class="token function">print</span><span class="token punctuation">(</span>tuple4<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/eadc528736794e1db7132addbea6c84f.png" alt="在这里插入图片描述" /><br /> count函数用于返回指定值次数&#xff1a;查找5出现次数</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
x <span class="token operator">&#61;</span> thistuple<span class="token punctuation">.</span><span class="token function">count</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7bc89e8e865749169b75b7fac7a97714.png" alt="在这里插入图片描述" /></p> 
<p>index()找出指定值并返回它的位置&#xff1a;查找元祖中8位置</p> 
<pre><code class="prism language-c">thistuple <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
x <span class="token operator">&#61;</span> thistuple<span class="token punctuation">.</span><span class="token function">index</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/4c73f269500641dab8ce0a82825760c5.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2569"></a>七.练习</h2> 
<p>1-使用正确的语法打印fruits元组中的第一项</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
print
</code></pre> 
<p>2-使用正确的语法打印fruits元组中的项目数。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
print
</code></pre> 
<p>3-使用负索引打印元组中的最后一项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">)</span>
print
</code></pre> 
<p>4-使用一系列索引打印元组中的第三、第四和第五项。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">(</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;orange&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;kiwi&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;melon&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>fruits<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/f306b51554a349c9a0357e9dcef34417.png" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_2601"></a>二十一、Python集合</h1> 
<h2><a id="_2603"></a>一.集合理解</h2> 
<p>基本形式&#xff1a;</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
</code></pre> 
<p>集合是用大括号写的。<br /> 创建一个集合&#xff1a;</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/acc7949313214a1690d93a0fe72254f2.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;集合是无序的&#xff0c;因此您无法确定项目的显示顺序。</p> 
<h2><a id="_2623"></a>二.访问集合</h2> 
<p><img src="https://img-blog.csdnimg.cn/9c4c031ed0694b79875c7c69a69891b0.png" alt="在这里插入图片描述" /></p> 
<h3><a id="21_2626"></a>2.1遍历集合</h3> 
<p>您不能通过引用索引或键来访问集合中的项目。但是您可以使用循环遍历集合项for &#xff0c;或者使用in关键字询问集合中是否存在指定的值 。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> i in myset<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/c85b0c99b2fa4b77a5549a4723987556.png" alt="在这里插入图片描述" /></p> 
<h3><a id="32_2640"></a>3.2检查是否存在</h3> 
<p>检查集合中是否存在“串串一号”&#xff1a;&#xff08;显然不在&#xff09;</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;串串一号&#39;</span> in myset<span class="token punctuation">)</span>
</code></pre> 
<p>返回布尔值&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f4dc1821c4c5468d8073f610175f141d.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2652"></a>三.添加集合</h2> 
<h3><a id="31_2654"></a>3.1添加项目值</h3> 
<p><img src="https://img-blog.csdnimg.cn/32647f43fb9b46488e87406069328e1c.png" alt="在这里插入图片描述" /></p> 
<p>创建集合后&#xff0c;您无法更改其项目&#xff0c;但可以添加新项目。要将一项添加到集合中&#xff0c;请使用add() 方法。<br /> 例如&#xff1a;添加川川菜鸟到集合中</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
myset<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/d2b039067a86419da44d2ca5b3894f33.png" alt="在这里插入图片描述" /></p> 
<h3><a id="32_2670"></a>3.2添加集合</h3> 
<p>要将另一个集合中的项目添加到当前集合中&#xff0c;请使用update() 方法。<br /> 例如将myset1添加到myset中&#xff1a;</p> 
<pre><code class="prism language-c">myset <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">}</span>
myset1 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span>myset1<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7b4314f3cc0249efa24cc1aed8755050.png" alt="在这里插入图片描述" /><br /> 为什么?别忘了我们的集合不能重复&#xff0c;重复的集合会被覆盖&#xff0c;因此只添加了新的值进来。</p> 
<h3><a id="33_2686"></a>3.3添加任何可迭代对象</h3> 
<p>update()方法中的对象不一定是集合&#xff0c;它可以是任何可迭代对象&#xff08;元组、列表、字典等&#xff09;。<br /> 例如&#xff1a;将myset2列表加入集合myset1</p> 
<pre><code class="prism language-c">myset1 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset2<span class="token operator">&#61;</span><span class="token punctuation">[</span><span class="token string">&#39;菜鸟&#39;</span><span class="token punctuation">,</span><span class="token string">&#39;川川&#39;</span><span class="token punctuation">]</span>
myset<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span>myset2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset<span class="token punctuation">)</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/80960e2edb48456c8a63aee5690b5ead.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2701"></a>四.移除集合项</h2> 
<h3><a id="41remove_2703"></a>4.1remove方法</h3> 
<p>要删除集合中的项目&#xff0c;请使用remove()、 或discard()方法。<br /> 例如我要移除川川菜鸟&#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset4<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset4<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/74b9ebe7aa8e4966b483235406c1be9d.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;如果要删除的项目不存在&#xff0c;remove()将引发错误。</p> 
<h3><a id="42discard__2718"></a>4.2discard() 方法</h3> 
<p>使用以下discard() 方法删除“川川菜鸟” &#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset4<span class="token punctuation">.</span><span class="token function">discard</span><span class="token punctuation">(</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset4<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/d2b4ea1a5fff440fa7dd68d0bb13fb6b.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;如果要删除的项目不存在&#xff0c;discard()则 不会引发错误。</p> 
<h3><a id="43pop__2732"></a>4.3pop() 方法</h3> 
<p>使用以下pop() 方法删除最后一项&#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset4<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset4<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6e4f314a4b71469aa9a61fedfcf7f9fc.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;集合是无序的&#xff0c;因此在使用该pop()方法时&#xff0c;您不知道哪个项目被删除。</p> 
<h3><a id="44clear__2746"></a>4.4clear() 方法</h3> 
<p>clear() 方法清空集合&#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset4<span class="token punctuation">)</span>
</code></pre> 
<p>打印为空。</p> 
<h3><a id="45del_2758"></a>4.5del关键字</h3> 
<p>该del关键字将完全删除该集合&#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
del myset4
</code></pre> 
<p>集合已经不存在了&#xff0c;因此我们不打印。</p> 
<h2><a id="_2769"></a>五.循环集合</h2> 
<p>for循环遍历即可</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
<span class="token keyword">for</span> i in myset4<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/29855bbdfb82437499f3b0278786de0e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2782"></a>六.集合连接</h2> 
<h3><a id="61_2784"></a>6.1普通连接</h3> 
<p>您可以使用union()返回包含两个集合中所有项的新集合的方法&#xff0c;或将一个集合中的所有项update()插入另一个集合的方法。<br /> 方法一&#xff1a;使用union()方法返回一个包含两个集合中所有项目的新集合</p> 
<pre><code class="prism language-c">set1 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;a&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;b&#34;</span> <span class="token punctuation">,</span> <span class="token string">&#34;c&#34;</span><span class="token punctuation">}</span>
set2 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span>

set3 <span class="token operator">&#61;</span> set1<span class="token punctuation">.</span><span class="token keyword">union</span><span class="token punctuation">(</span>set2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>set3<span class="token punctuation">)</span>
</code></pre> 
<p>方法二&#xff1a;update()方法将 set2 中的项插入到 set1 中</p> 
<pre><code class="prism language-c">set1 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;a&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;b&#34;</span> <span class="token punctuation">,</span> <span class="token string">&#34;c&#34;</span><span class="token punctuation">}</span>
set2 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">}</span>

set1<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span>set2<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>set1<span class="token punctuation">)</span>
</code></pre> 
<p><strong>注意</strong>&#xff1a;无论union()和update() 将排除任何重复的项目。</p> 
<h3><a id="62_2809"></a>6.2仅保留重复项</h3> 
<p>intersection_update()方法将只保留两个集合中都存在的项目。<br /> 保留myset4和myset5重复项&#xff1a;</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset5 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川五号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset4<span class="token punctuation">.</span><span class="token function">intersection_update</span><span class="token punctuation">(</span>myset5<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>myset4<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/61e1c6a4c6804df9b2d269ed47a24c1f.png" alt="在这里插入图片描述" /></p> 
<p>或者用intersection()方法将返回一个新集合&#xff0c;该集合仅包含两个集合中都存在的项目。</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset5 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川五号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
z<span class="token operator">&#61;</span>myset4<span class="token punctuation">.</span><span class="token function">intersection</span><span class="token punctuation">(</span>myset5<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/3ed40f6818dd466cb021fcb85f05dee4.png" alt="在这里插入图片描述" /></p> 
<h3><a id="63_2835"></a>6.3保留所有&#xff0c;但不保留重复项</h3> 
<p>symmetric_difference_update()方法将只保留两个集合中都不存在的元素。</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset5 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川五号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
z<span class="token operator">&#61;</span>myset4<span class="token punctuation">.</span><span class="token function">symmetric_difference_update</span><span class="token punctuation">(</span>myset5<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a141525d488649c4afa5c999725f21ce.png" alt="在这里插入图片描述" /></p> 
<p>symmetric_difference()方法将返回一个新集合&#xff0c;该集合仅包含两个集合中都不存在的元素。</p> 
<pre><code class="prism language-c">myset4 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川二号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
myset5 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;川川一号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川五号&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;川川三号&#34;</span><span class="token punctuation">,</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span>
z<span class="token operator">&#61;</span>myset4<span class="token punctuation">.</span><span class="token function">symmetric_difference</span><span class="token punctuation">(</span>myset5<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8b9b6d5b98404ff18cb9c10078a21ad9.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_2860"></a>七.练习</h2> 
<p>1-检查fruits集中是否存在“appl”。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>
<span class="token keyword">if</span> <span class="token string">&#34;apple&#34;</span>   fruits<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Yes, apple is a fruit!&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>2-使用 add 方法将“orange”添加到fruits集中。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>

</code></pre> 
<p>3-使用正确的方法将多个项目&#xff08;more_fruits&#xff09;添加到fruits 集中。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>
more_fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;orange&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;mango&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;grapes&#34;</span><span class="token punctuation">]</span>
fruits<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span>more_fruits<span class="token punctuation">)</span>#答案
</code></pre> 
<p>4-使用 remove 方法从fruits 集中删除“banana。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>

</code></pre> 
<p>5-使用discard方法从fruits 集中删除“香蕉”。</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">}</span>

</code></pre> 
<h1><a id="Python_2899"></a>二十二、Python字典</h1> 
<h2><a id="_2901"></a>一.字典理解</h2> 
<p>基本形式&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>
</code></pre> 
<p>字典用于在键值对中存储数据值。字典是有序*、可变且不允许重复的集合。&#xff08;从 Python 3.7 版开始&#xff0c;字典是有序的。在 Python 3.6 及更早版本中&#xff0c;字典是无序的。&#xff09;</p> 
<h3><a id="11_2915"></a>1.1创建字典与访问</h3> 
<p>字典是用大括号写的&#xff0c;有键和值。<br /> 创建并打印字典&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>字典项是有序的、可变的&#xff0c;并且不允许重复。字典项以键值对的形式呈现&#xff0c;可以使用键名进行引用。<br /> 例如打印brand的值</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">[</span><span class="token string">&#34;brand&#34;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>字典不能有两个具有相同键的项目&#xff1a;重复值将覆盖现有值<br /> 返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b87beb1c6de84aa18916719969a360a9.png" alt="在这里插入图片描述" /></p> 
<h3><a id="12_2945"></a>1.2字典长度</h3> 
<p>还是用用len函数</p> 
<pre><code class="prism language-c">hisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2020</span>
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="13_2959"></a>1.3数据类型</h3> 
<p>字典项中的值可以是任何数据类型&#xff1a;<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;electric&#34;</span><span class="token operator">:</span> False<span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span><span class="token punctuation">,</span>
  <span class="token string">&#34;colors&#34;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&#34;red&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;white&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;blue&#34;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> 
<p>类型&#xff1a;dict()<br /> 打印字典的数据类型&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>补充巩固&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e505069070754184ae9a6695c6371db7.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_30,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h2><a id="_2988"></a>二.访问字典</h2> 
<p><img src="https://img-blog.csdnimg.cn/f9ca37c41656435c956192378b10c710.png" alt="在这里插入图片描述" /></p> 
<h3><a id="21_2992"></a>2.1访问键名</h3> 
<p>您可以通过引用方括号内的键名来访问字典的项目&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
x <span class="token operator">&#61;</span> thisdict<span class="token punctuation">[</span><span class="token string">&#34;name&#34;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>还有一个被调用的方法get()会给你同样的结果&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
x <span class="token operator">&#61;</span> thisdict<span class="token punctuation">[</span><span class="token string">&#34;name&#34;</span><span class="token punctuation">]</span>
y<span class="token operator">&#61;</span>thisdict<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/283fa97d655c4db7b73c49892c97e29e.png" alt="在这里插入图片描述" /></p> 
<h3><a id="22_3023"></a>2.2访问健值</h3> 
<p>keys()方法将返回字典中所有键的列表。</p> 
<pre><code class="prism language-c">hisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
x <span class="token operator">&#61;</span> thisdict<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>向原始字典<strong>添加</strong>一个新项目&#xff0c;并看到键列表也得到更新&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">[</span><span class="token string">&#39;age&#39;</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token number">20</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a6f930e5eabc4c5c8080e12104a6d0af.png" alt="在这里插入图片描述" /><br /> <strong>获取值</strong><br /> values()方法将返回字典中所有值的列表。</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> thisdict<span class="token punctuation">.</span><span class="token function">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>items()方法将返回字典中的每个项目&#xff0c;作为列表中的元组。</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">[</span><span class="token string">&#39;age&#39;</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token number">20</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
x <span class="token operator">&#61;</span> thisdict<span class="token punctuation">.</span><span class="token function">items</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回元祖&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/02b4b8a9041a4737bac9adf292977664.png" alt="在这里插入图片描述" /><br /> 要确定字典中是否存在指定的键&#xff0c;请使用in关键字&#xff1a;</p> 
<pre><code class="prism language-c">hisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">if</span> <span class="token string">&#39;name&#39;</span> in thisdict<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#39;name在字典&#39;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/afa9e11e6074420889df6f4d1b8828f2.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3089"></a>三.更改字典各种方法</h2> 
<p>前面我们讲到了一部分更改内容&#xff0c;这里我们具体讲一下。<br /> 例如我要把川川改为川川菜鸟&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span> <span class="token operator">&#61;</span> <span class="token string">&#39;川川菜鸟&#39;</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6682fb216d08467a94f49788575dd43e.png" alt="在这里插入图片描述" /></p> 
<p>或者我们使用update()方法&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span><span class="token string">&#39;name&#39;</span><span class="token operator">:</span><span class="token string">&#39;川川菜鸟&#39;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>效果一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e387f4f304f3498184c32f16881d5fdc.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3122"></a>四.添加字典项各种方法</h2> 
<p>比如我要添加一个年龄为20&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">[</span><span class="token string">&#39;age&#39;</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token number">20</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<img src="https://img-blog.csdnimg.cn/7ca3fddcf9c243e2bc0df1db65ea370b.png" alt="在这里插入图片描述" /></p> 
<p>或者还是使用update:</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">[</span><span class="token string">&#39;age&#39;</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token number">20</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
thisdict<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span><span class="token punctuation">{<!-- --></span><span class="token string">&#39;age&#39;</span><span class="token operator">:</span><span class="token string">&#39;20岁&#39;</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/bb73cb2ffdd049c98bd60c321627fa8d.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3155"></a>五.删除字典的各种方法</h2> 
<p>pop()方法删除具有指定键名的项。<br /> 比如我要删除地址项目&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token string">&#34;address&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e5e3a007e23541618ee1ca27a624f97b.png" alt="在这里插入图片描述" /></p> 
<p>popitem()方法删除最后插入的项目&#xff08;在 3.7 之前的版本中&#xff0c;将删除随机项目&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token string">&#34;address&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
thisdict<span class="token punctuation">.</span><span class="token function">popitem</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9bc65c1c8d1d4ffbac10b0d4ee64a9f5.png" alt="在这里插入图片描述" /></p> 
<p>del关键字删除与指定键名称的项目&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
del thisdict<span class="token punctuation">[</span><span class="token string">&#39;name&#39;</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9d3fbc72b55c4404816adecb66c9693a.png" alt="在这里插入图片描述" /></p> 
<p>del关键字也可以删除字典完全&#xff1a;</p> 
<pre><code class="prism language-c">del thisdict
</code></pre> 
<p>clear()方法清空字典&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
thisdict<span class="token punctuation">.</span><span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
</code></pre> 
<p>返回空&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/67c794439ec04d1fb61be72a4fdd53a7.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3226"></a>六.遍历字典</h2> 
<p>将字典中的所有键名&#xff0c;一一打印出来&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">for</span> x in thisdict<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>一一打印字典中的所有值&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">for</span> x in thisdict<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">[</span>x<span class="token punctuation">]</span><span class="token punctuation">)</span>

</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f34fc65c4a114c88b0947ca604ff474c.png" alt="在这里插入图片描述" /><br /> 您还可以使用该values()方法返回字典的值&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">for</span> x in thisdict<span class="token punctuation">.</span><span class="token function">values</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>您可以使用该keys()方法返回字典的键&#xff1a;</p> 
<pre><code class="prism language-c">hisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">for</span> x in thisdict<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a06b84d9abff4f02a5251b71d9600202.png" alt="在这里插入图片描述" /><br /> 使用以下 方法循环遍历keys和valuesitems()&#xff1a;</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
<span class="token keyword">for</span> x<span class="token punctuation">,</span> y in thisdict<span class="token punctuation">.</span><span class="token function">items</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/455f3dabb3d54865901bf7cc849b2dd0.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3296"></a>七.复制字典</h2> 
<p>用copy()函数</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
mydict<span class="token operator">&#61;</span>thisdict<span class="token punctuation">.</span><span class="token function">copy</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mydict<span class="token punctuation">)</span>
</code></pre> 
<p>内置dict(&#xff09;函数</p> 
<pre><code class="prism language-c">thisdict <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;address&#34;</span><span class="token operator">:</span> <span class="token string">&#34;上海&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">2000</span>
<span class="token punctuation">}</span>
mydict<span class="token operator">&#61;</span><span class="token function">dict</span><span class="token punctuation">(</span>thisdict<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>mydict<span class="token punctuation">)</span>
</code></pre> 
<p>效果都一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/7a8d876d92cc4d709ed06e8cd051151e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3325"></a>八.嵌套字典</h2> 
<p>创建一个包含三个字典的字典&#xff1a;</p> 
<pre><code class="prism language-c">myfamily <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;child1&#34;</span> <span class="token operator">:</span> <span class="token punctuation">{<!-- --></span>
    <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Emil&#34;</span><span class="token punctuation">,</span>
    <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2004</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token string">&#34;child2&#34;</span> <span class="token operator">:</span> <span class="token punctuation">{<!-- --></span>
    <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Tobias&#34;</span><span class="token punctuation">,</span>
    <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2007</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token string">&#34;child3&#34;</span> <span class="token operator">:</span> <span class="token punctuation">{<!-- --></span>
    <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Linus&#34;</span><span class="token punctuation">,</span>
    <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2011</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span>myfamily<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2b775bdbc83449e398dbef33f2698d3d.png" alt="在这里插入图片描述" /><br /> 创建三个字典&#xff0c;然后创建一个包含其他三个字典的字典&#xff1a;</p> 
<pre><code class="prism language-c">child1 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Emil&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2004</span>
<span class="token punctuation">}</span>
child2 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Tobias&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2007</span>
<span class="token punctuation">}</span>
child3 <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span> <span class="token operator">:</span> <span class="token string">&#34;Linus&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span> <span class="token operator">:</span> <span class="token number">2011</span>
<span class="token punctuation">}</span>

myfamily <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;child1&#34;</span> <span class="token operator">:</span> child1<span class="token punctuation">,</span>
  <span class="token string">&#34;child2&#34;</span> <span class="token operator">:</span> child2<span class="token punctuation">,</span>
  <span class="token string">&#34;child3&#34;</span> <span class="token operator">:</span> child3
<span class="token punctuation">}</span>
<span class="token function">print</span><span class="token punctuation">(</span>myfamily<span class="token punctuation">)</span>
</code></pre> 
<p>效果一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4c55319b19ec4cdfaf2dd177f46cd4f5.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3376"></a>九.练习</h2> 
<p>1-使用get方法打印汽车字典的“model”键的值。</p> 
<pre><code class="prism language-c">car <span class="token operator">&#61;</span>	<span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>
print
</code></pre> 
<p>2-将“year”值从 1964 更改为 2020。</p> 
<pre><code class="prism language-c">car <span class="token operator">&#61;</span>	<span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>

</code></pre> 
<p>3-将键/值对 “color” : “red” 添加到汽车字典中。</p> 
<pre><code class="prism language-c">car <span class="token operator">&#61;</span>	<span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>

</code></pre> 
<p>4-使用 pop 方法从汽车字典中删除“model”。</p> 
<pre><code class="prism language-c">car <span class="token operator">&#61;</span>	<span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>

</code></pre> 
<p>5-使用clear方法清空car字典。</p> 
<pre><code class="prism language-c">car <span class="token operator">&#61;</span>	<span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;brand&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Ford&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;model&#34;</span><span class="token operator">:</span> <span class="token string">&#34;Mustang&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;year&#34;</span><span class="token operator">:</span> <span class="token number">1964</span>
<span class="token punctuation">}</span>

</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/c38b0baf6c0d45eb8143b76bda8a2969.png" alt="在这里插入图片描述" /></p> 
<h1><a id="If__Else_3434"></a>二十三、If … Else语句</h1> 
<p>Python 支持数学中常见的逻辑条件&#xff1a;</p> 
<ul><li>等于&#xff1a;a &#61;&#61; b</li><li>不等于&#xff1a;a !&#61; b</li><li>小于&#xff1a;a &lt; b</li><li>小于或等于&#xff1a;a &lt;&#61; b</li><li>大于&#xff1a;a &gt; b</li><li>大于或等于&#xff1a;a &gt;&#61; b</li></ul> 
<h2><a id="if_3445"></a>一.if语句</h2> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">33</span>
b <span class="token operator">&#61;</span> <span class="token number">200</span>
<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 大于 a&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/878b478c7f94453a8bc2f25cbec27f31.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>:if后面要有冒号<br /> 在这个例子中&#xff0c;我们使用两个变量a和b&#xff0c;它们用作 if 语句的一部分来测试b是否大于a。由于a是33&#xff0c;而b是200&#xff0c;我们知道 200 大于 33&#xff0c;所以我们打印到屏幕上“b 大于 a”。</p> 
<h2><a id="_3459"></a>二.缩进</h2> 
<p>Python 依靠缩进&#xff08;行首的空格&#xff09;来定义代码中的范围。为此&#xff0c;其他编程语言通常使用大括号。<br /> If 语句&#xff0c;没有缩进&#xff08;会引发错误&#xff09;&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">33</span>
b <span class="token operator">&#61;</span> <span class="token number">200</span>
<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 大于 a&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="elif_3471"></a>三.elif语句</h2> 
<p><img src="https://img-blog.csdnimg.cn/783ca06b83c442bdabbc3c02c2fe964a.png" alt="在这里插入图片描述" /></p> 
<p>如果前面的条件是不正确的&#xff0c;那就试试这个条件。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">33</span>
b <span class="token operator">&#61;</span> <span class="token number">33</span>
<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 大于 a&#34;</span><span class="token punctuation">)</span>
elif a <span class="token operator">&#61;&#61;</span> b<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;a 等于b&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9345cc2c3c5d48d4877abf6d7693d193.png" alt="在这里插入图片描述" /></p> 
<p>在这个例子中a等于b&#xff0c;所以第一个条件不成立&#xff0c;但elif条件成立&#xff0c;所以我们打印到屏幕“a 和 b 相等”</p> 
<h2><a id="else_3492"></a>四.else语句</h2> 
<h3><a id="41else_3493"></a>4.1基本else</h3> 
<p>在其他关键字捕获任何未通过前面的条件抓获。</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">200</span>
b <span class="token operator">&#61;</span> <span class="token number">33</span>
<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 大于 a&#34;</span><span class="token punctuation">)</span>
elif a <span class="token operator">&#61;&#61;</span> b<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;a 等于b&#34;</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;a 小于 b&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/be75c187a15e4f7fb02709be7e288c72.png" alt="在这里插入图片描述" /><br /> 在这个例子中a大于b&#xff0c;所以第一个条件不成立&#xff0c;elif条件也不成立&#xff0c;所以我们转到else条件并打印到屏幕“a 小于 b”。</p> 
<p>你也可以有一个else没有 elif&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">200</span>
b <span class="token operator">&#61;</span> <span class="token number">33</span>
<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 大于 a&#34;</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;b 小于 a&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="42and_3523"></a>4.2and语句</h3> 
<p>测试 if a是否大于 b&#xff0c;并且 if c 大于a&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">200</span>
b <span class="token operator">&#61;</span> <span class="token number">33</span>
c <span class="token operator">&#61;</span> <span class="token number">500</span>
<span class="token keyword">if</span> a <span class="token operator">&gt;</span> b and c <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;两种条件都满足&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="43or__3532"></a>4.3or 语句</h3> 
<p>测试 if a是否大于 b&#xff0c;或 if a 大于c&#xff1a;</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">200</span>
b <span class="token operator">&#61;</span> <span class="token number">33</span>
c <span class="token operator">&#61;</span> <span class="token number">500</span>
<span class="token keyword">if</span> a <span class="token operator">&gt;</span> b or a <span class="token operator">&gt;</span> c<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;At least one of the conditions is True&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="44if_3541"></a>4.4嵌套if语句</h3> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token number">41</span>
<span class="token keyword">if</span> x <span class="token operator">&gt;</span> <span class="token number">10</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Above ten,&#34;</span><span class="token punctuation">)</span>
  <span class="token keyword">if</span> x <span class="token operator">&gt;</span> <span class="token number">20</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;and also above 20!&#34;</span><span class="token punctuation">)</span>
  <span class="token keyword">else</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;but not above 20.&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="44pass_3552"></a>4.4pass语句</h3> 
<p>if语句不能为空&#xff0c;但如果您出于某种原因有一个if没有内容&#xff0c;pass语句请放入该语句以避免出错。</p> 
<pre><code class="prism language-c">a <span class="token operator">&#61;</span> <span class="token number">33</span>
b <span class="token operator">&#61;</span> <span class="token number">200</span>

<span class="token keyword">if</span> b <span class="token operator">&gt;</span> a<span class="token operator">:</span>
  pass
</code></pre> 
<h1><a id="while_3562"></a>二十四、while循环语句</h1> 
<h2><a id="_3563"></a>一.基本理解</h2> 
<p>使用while循环&#xff0c;只要条件为真&#xff0c;我们就可以执行一组语句。<br /> 例如&#xff1a;只要 i 小于 6 就打印 i</p> 
<pre><code class="prism language-c">i <span class="token operator">&#61;</span> <span class="token number">1</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token number">6</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
  i <span class="token operator">&#43;&#61;</span> <span class="token number">1</span>
</code></pre> 
<p>返回为&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/14e55ef2832742c1bb32a30302abfd28.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;记住要限制 i&#xff0c;否则循环将永远持续下去。</p> 
<h2><a id="_3576"></a>二.中断声明</h2> 
<p>使用break语句&#xff0c;即使 while 条件为真&#xff0c;我们也可以停止循环&#xff1a;<br /> 例如当 i 为 3 时退出循环&#xff1a;</p> 
<pre><code class="prism language-c">i <span class="token operator">&#61;</span> <span class="token number">1</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token number">6</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
  <span class="token keyword">if</span> i <span class="token operator">&#61;&#61;</span> <span class="token number">3</span><span class="token operator">:</span>
    <span class="token keyword">break</span>
  i <span class="token operator">&#43;&#61;</span> <span class="token number">1</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/78079ceeb9784cdd8f939001cbda9d71.png" alt="在这里插入图片描述" /></p> 
<h2><a id="continue__3591"></a>三.continue 声明</h2> 
<p>使用continue语句&#xff0c;我们可以停止当前的迭代&#xff0c;并继续下一个&#xff1a;</p> 
<pre><code class="prism language-c">i <span class="token operator">&#61;</span> <span class="token number">0</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token number">6</span><span class="token operator">:</span>
  i <span class="token operator">&#43;&#61;</span> <span class="token number">1</span>
  <span class="token keyword">if</span> i <span class="token operator">&#61;&#61;</span> <span class="token number">3</span><span class="token operator">:</span>
    <span class="token keyword">continue</span>
  <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;可以并没有打印3<br /> <img src="https://img-blog.csdnimg.cn/97479b5c3a514dd081f94b3c4f99aa91.png" alt="在这里插入图片描述" /></p> 
<h2><a id="else__3604"></a>四.else 语句</h2> 
<p>使用else语句&#xff0c;当条件不再为真时&#xff0c;我们可以运行一次代码块&#xff1a;<br /> 一旦条件为假&#xff0c;打印一条消息&#xff1a;</p> 
<pre><code class="prism language-c">i <span class="token operator">&#61;</span> <span class="token number">1</span>
<span class="token keyword">while</span> i <span class="token operator">&lt;</span> <span class="token number">6</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
  i <span class="token operator">&#43;&#61;</span> <span class="token number">1</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;i is no longer less than 6&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p><img src="https://img-blog.csdnimg.cn/d897e5ec142b47e88db212fdb53f22ee.png" alt="在这里插入图片描述" /></p> 
<h1><a id="for_3618"></a>二十五、for循环语句</h1> 
<h2><a id="_3619"></a>一.基本遍历</h2> 
<p>使用for循环&#xff0c;我们可以执行一组语句&#xff0c;对列表、元组、集合等中的每个项目执行一次。<br /> 例如&#xff1a;打印水果列表中的每个水果</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> x in fruits<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_3628"></a>二.遍历字符串</h2> 
<p>例如循环遍历单词“banana”中的字母&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token keyword">for</span> x in <span class="token string">&#34;banana&#34;</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_3635"></a>三.中断声明</h2> 
<p>使用break语句&#xff0c;我们可以在循环遍历所有项目之前停止循环.<br /> 例如当x是“banana”时退出循环&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> x in fruits<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
  <span class="token keyword">if</span> x <span class="token operator">&#61;&#61;</span> <span class="token string">&#34;banana&#34;</span><span class="token operator">:</span>
    <span class="token keyword">break</span>

</code></pre> 
<p>当x是“banana”时退出循环&#xff0c;但这次中断出现在打印之前&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> x in fruits<span class="token operator">:</span>
  <span class="token keyword">if</span> x <span class="token operator">&#61;&#61;</span> <span class="token string">&#34;banana&#34;</span><span class="token operator">:</span>
    <span class="token keyword">break</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>就会返回只有applr:<br /> <img src="https://img-blog.csdnimg.cn/4b09ae5dbf00421796cb4ab9cf2c9acc.png" alt="在这里插入图片描述" /></p> 
<h2><a id="continue__3658"></a>四.continue 声明</h2> 
<p>使用continue语句&#xff0c;我们可以停止循环的当前迭代&#xff0c;并继续下一个&#xff1a;<br /> 不要打印banana&#xff1a;</p> 
<pre><code class="prism language-c">fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> x in fruits<span class="token operator">:</span>
  <span class="token keyword">if</span> x <span class="token operator">&#61;&#61;</span> <span class="token string">&#34;banana&#34;</span><span class="token operator">:</span>
    <span class="token keyword">continue</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>

</code></pre> 
<h2><a id="range__3670"></a>五.range() 函数</h2> 
<p>要循环一组代码指定的次数&#xff0c;我们可以使用range()函数&#xff0c;的范围&#xff08;&#xff09;函数返回由1个数字&#xff0c;通过默认从0开始&#xff0c;并递增的顺序&#xff08;缺省&#xff09;&#xff0c;并结束在指定次数。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c"><span class="token keyword">for</span> x in <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/3c98afbedeb041e1b4cb985ef33a167e.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong> range(6)不是 0 到 6 的值&#xff0c;而是 0 到 5 的值。<br /> range函数默认被1至递增序列&#xff0c;但是有可能通过增加第三参数指定增量值&#xff1a;range&#xff08;2&#xff0c;30&#xff0c;3&#xff09;</p> 
<h2><a id="_3681"></a>六.嵌套循环</h2> 
<p>嵌套循环是循环内的循环。“内循环”将在“外循环”的每次迭代中执行一次。<br /> 为每个fruits打印每个形容词&#xff1a;</p> 
<pre><code class="prism language-c">adj <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;red&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;big&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;tasty&#34;</span><span class="token punctuation">]</span>
fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>

<span class="token keyword">for</span> x in adj<span class="token operator">:</span>
  <span class="token keyword">for</span> y in fruits<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/db9d8a6845c3434ebc19a66b87677f17.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_24,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h2><a id="pass_3694"></a>七.pass语句</h2> 
<p>for循环不能为空&#xff0c;但如果由于某种原因有一个for没有内容的循环&#xff0c;请放入pass语句以避免出错。</p> 
<pre><code class="prism language-c"><span class="token keyword">for</span> x in <span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token operator">:</span>
  pass
</code></pre> 
<h1><a id="_3701"></a>二十六、函数</h1> 
<p><img src="https://img-blog.csdnimg.cn/05f0f06cd4c74925b33da30d089b6e3e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3704"></a>一.创建函数与调用</h2> 
<p>在 Python 中&#xff0c;函数是使用def 关键字定义的&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello from a function&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p><strong>调用函数</strong><br /> 要调用函数&#xff0c;请使用函数名称后跟括号&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/97d6ee5e947a4ae9b88fd39eb46c3aee.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3721"></a>二.参数</h2> 
<p>信息可以作为参数传递给函数。参数在函数名后的括号内指定。您可以根据需要添加任意数量的参数&#xff0c;只需用逗号分隔它们。</p> 
<p>下面的示例有一个带一个参数 (fname) 的函数。当函数被调用时&#xff0c;我们传递一个名字&#xff0c;在函数内部使用它来打印全名&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>fname<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>fname <span class="token operator">&#43;</span> <span class="token string">&#34; 菜鸟&#34;</span><span class="token punctuation">)</span>

<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;川川吗&#34;</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;憨批&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2ec46a81c80142979e635c08c8dfb926.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3736"></a>三.参数数量</h2> 
<p>默认情况下&#xff0c;必须使用正确数量的参数调用函数。这意味着如果您的函数需要 2 个参数&#xff0c;则必须使用 2 个参数调用该函数&#xff0c;不能多也不能少。</p> 
<p>例如此函数需要 2 个参数&#xff0c;并获得 2 个参数&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>fname <span class="token operator">&#43;</span> <span class="token string">&#34; &#34;</span> <span class="token operator">&#43;</span> lname<span class="token punctuation">)</span>

<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/04b887581c834f7eabca564cd5b8128e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="args_3749"></a>四.任意参数&#xff0c;*args</h2> 
<p><img src="https://img-blog.csdnimg.cn/3605a84f6caf40fc94ca36a5f597953d.png" alt="在这里插入图片描述" /></p> 
<p>如果您不知道将传递给函数的参数有多少&#xff0c;请*在函数定义中的参数名称前添加一个。这样&#xff0c;该函数将接收一个参数元组&#xff0c;并可以相应地访问这些项目。</p> 
<p>如果参数数量未知&#xff0c;则*在参数名称前添加一个&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span><span class="token operator">*</span>kids<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;川川帅哥 &#34;</span> <span class="token operator">&#43;</span> kids<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;名字&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;性别&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/ad4f2945e867491cad3f217f445b1b12.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3763"></a>五.关键字参数</h2> 
<p>您还可以使用key &#61; value语法发送参数。这样&#xff0c;参数的顺序就无关紧要了。</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>child3<span class="token punctuation">,</span> child2<span class="token punctuation">,</span> child1<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;最帅的是 &#34;</span> <span class="token operator">&#43;</span> child3<span class="token punctuation">)</span>

<span class="token function">my_function</span><span class="token punctuation">(</span>child1 <span class="token operator">&#61;</span> <span class="token string">&#34;大白&#34;</span><span class="token punctuation">,</span> child2 <span class="token operator">&#61;</span> <span class="token string">&#34;小白&#34;</span><span class="token punctuation">,</span> child3 <span class="token operator">&#61;</span> <span class="token string">&#34;猪猪侠&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f6069d98fbeb401792bb4c193f19607a.png" alt="在这里插入图片描述" /></p> 
<p>短语关键字参数在 Python 文档中通常缩写为kwargs。</p> 
<h2><a id="kwargs_3776"></a>七.任意关键字参数&#xff0c;**kwargs</h2> 
<p>如果您不知道有多少关键字参数将被传递到您的函数中&#xff0c;请**在函数定义中的参数名称之前添加两个星号。这样&#xff0c;该函数将接收一个参数字典&#xff0c;并可以相应地访问这些项目.<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token operator">*</span>kid<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;它的名字是 &#34;</span> <span class="token operator">&#43;</span> kid<span class="token punctuation">[</span><span class="token string">&#34;lname&#34;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>

<span class="token function">my_function</span><span class="token punctuation">(</span>fname <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> lname <span class="token operator">&#61;</span> <span class="token string">&#34;川川&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/02fac1a1e0704e3d9eeec9ad0e569e34.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3787"></a>八.默认参数值</h2> 
<p>如果我们不带参数调用函数&#xff0c;它使用默认值&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>country <span class="token operator">&#61;</span> <span class="token string">&#34;Norway&#34;</span><span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;I am from &#34;</span> <span class="token operator">&#43;</span> country<span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;Sweden&#34;</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;India&#34;</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">my_function</span><span class="token punctuation">(</span><span class="token string">&#34;Brazil&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9d2b196eae424cb89f732c8f96cd6d86.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3800"></a>九将列表作为参数传递</h2> 
<p>例如&#xff0c;如果你发送一个 List 作为参数&#xff0c;当它到达函数时它仍然是一个 List&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>food<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token keyword">for</span> x in food<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
fruits <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;apple&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;banana&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;cherry&#34;</span><span class="token punctuation">]</span>
<span class="token function">my_function</span><span class="token punctuation">(</span>fruits<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2c25901fc7974f799f4cfa0997ba2968.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3812"></a>十.返回值</h2> 
<p>要让函数返回值&#xff0c;请使用以下return 语句&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">my_function</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token keyword">return</span> <span class="token number">5</span> <span class="token operator">*</span> x

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">my_function</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">my_function</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">my_function</span><span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="pass_3823"></a>十一.pass语句</h2> 
<p>function定义不能为空&#xff0c;但如果您出于某种原因有一个function没有内容的定义&#xff0c;请放入pass语句中以避免出错。</p> 
<pre><code class="prism language-c">def <span class="token function">myfunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span>
  pass
</code></pre> 
<h1><a id="lambda_3830"></a>二十七、lambda</h1> 
<p><img src="https://img-blog.csdnimg.cn/747a9364e8b0492484bc0b46fdab3f94.png" alt="在这里插入图片描述" /></p> 
<p>lambda 函数是一个小的匿名函数。一个 lambda 函数可以接受任意数量的参数&#xff0c;但只能有一个表达式。<br /> 语法&#xff1a;<br /> <code>lambda arguments : expression</code><br /> 执行表达式并返回结果&#xff1a;</p> 
<p>示例将 10 添加到 argument a&#xff0c;并返回结果&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> lambda a <span class="token operator">:</span> a <span class="token operator">&#43;</span> <span class="token number">10</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">x</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4eb10ffee5364c719ee3733248578248.png" alt="在这里插入图片描述" /><br /> Lambda 函数可以接受任意数量的参数。<br /> 例将参数a与参数 相乘b并返回结果&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> lambda a<span class="token punctuation">,</span> b <span class="token operator">:</span> a <span class="token operator">*</span> b
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">x</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/35ac69bf4b854d469ba7aeaceceaa9d6.png" alt="在这里插入图片描述" /><br /> 把参数a、 b和c并返回结果&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> lambda a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c <span class="token operator">:</span> a <span class="token operator">&#43;</span> b <span class="token operator">&#43;</span> c
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">x</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/89bc1de6ef1b40dcad467ed716bb9596.png" alt="在这里插入图片描述" /><br /> 假设您有一个接受一个参数的函数定义&#xff0c;并且该参数将乘以一个未知数&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">myfunc</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token keyword">return</span> lambda a <span class="token operator">:</span> a <span class="token operator">*</span> n
</code></pre> 
<p>使用该函数定义来创建一个函数&#xff0c;该函数始终将您发送的数字加倍&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">myfunc</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token keyword">return</span> lambda a <span class="token operator">:</span> a <span class="token operator">*</span> n
mydoubler <span class="token operator">&#61;</span> <span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">mydoubler</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>使用相同的函数定义来创建一个始终将您发送的数字增加三倍的函数&#xff1a;</p> 
<pre><code class="prism language-c">def <span class="token function">myfunc</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token operator">:</span>
  <span class="token keyword">return</span> lambda a <span class="token operator">:</span> a <span class="token operator">*</span> n

mytripler <span class="token operator">&#61;</span> <span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">mytripler</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h1><a id="_3888"></a>二十八、数组</h1> 
<p><img src="https://img-blog.csdnimg.cn/3da7a15bfed34d2a8c2551c38257522d.png" alt="在这里插入图片描述" /></p> 
<p>Python 没有对数组的内置支持&#xff0c;但可以使用Python 列表代替。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
</code></pre> 
<h2><a id="_3896"></a>一.访问数组的元素</h2> 
<p>您可以通过引用索引号来引用数组元素。例如&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
te<span class="token operator">&#61;</span>chuan<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
<span class="token function">print</span><span class="token punctuation">(</span>te<span class="token punctuation">)</span>
</code></pre> 
<p>修改数组&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
chuan<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token string">&#39;高富帅&#39;</span>
<span class="token function">print</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<img src="https://img-blog.csdnimg.cn/4a06fdd98a6f41518868924ffc0103d7.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_3913"></a>二.数组的长度</h2> 
<p>用len函数。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
chuan<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">&#61;</span><span class="token string">&#39;高富帅&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span></span></span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">len</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_3923"></a>三.修改数组</h2> 
<p>补充一点&#xff1a;循环数组元素&#xff0c;您可以使用for in循环遍历数组的所有元素。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
<span class="token keyword">for</span> i in chuan<span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>
</code></pre> 
<p><strong>添加数组元素</strong><br /> 使用append函数&#xff08;跟列表一样&#xff09;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
chuan<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&#39;上海&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/2dc8194f6fad4e22a96fc6b71a3d20be.png" alt="在这里插入图片描述" /><br /> <strong>删除数组元素</strong><br /> 您可以使用该pop()方法从数组中删除一个元素。&#xff08;注意起始位置是0&#xff09;<br /> 例如删除第二个元素&#xff1a;</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
chuan<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/5fec18098ea94702b4c396ef1ca8fbcc.png" alt="在这里插入图片描述" /><br /> 您还可以使用该remove()方法从数组中删除一个元素。</p> 
<pre><code class="prism language-c">chuan <span class="token operator">&#61;</span> <span class="token punctuation">[</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;帅哥&#34;</span><span class="token punctuation">]</span>
chuan<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span>
chuan<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">&#39;帅哥&#39;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>chuan<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6f4687037c364aef88d8e040ef1380e5.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;列表的remove()方法只删除指定值的第一次出现。</p> 
<h2><a id="_3965"></a>四.数组的其它操作</h2> 
<p><img src="https://img-blog.csdnimg.cn/1a366b94e1e04424b6d7a88286749a27.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_40,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_3967"></a>二十九、Python类和对象</h1> 
<p><img src="https://img-blog.csdnimg.cn/65b518817f514a8480a989a8ffd24a5b.png" alt="在这里插入图片描述" /></p> 
<p>Python 类/对象。Python 是一种面向对象的编程语言。Python 中的几乎所有东西都是一个对象&#xff0c;有它的属性和方法。类就像一个对象构造函数&#xff0c;或者是创建对象的“蓝图”。</p> 
<h2><a id="_3971"></a>一.创建类</h2> 
<p>要创建一个类&#xff0c;请使用关键字<strong>class</strong>。<br /> 例如&#xff1a;创建一个名为 MyClass 的类&#xff0c;其属性名为 x</p> 
<pre><code class="prism language-c">class MyClass<span class="token operator">:</span>
  x <span class="token operator">&#61;</span> <span class="token number">5</span>
<span class="token function">print</span><span class="token punctuation">(</span>MyClass<span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_3981"></a>二.创建对象</h2> 
<p>现在我们可以使用名为 MyClass 的类来创建对象。<br /> 例如创建一个名为 p1 的对象&#xff0c;并打印 x 的值&#xff1a;</p> 
<pre><code class="prism language-c">class MyClass<span class="token operator">:</span>
  x <span class="token operator">&#61;</span> <span class="token number">5</span>
p1 <span class="token operator">&#61;</span> <span class="token function">MyClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">.</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6b1e869957464d94b726b3b8a8ca93f7.png" alt="在这里插入图片描述" /></p> 
<h2><a id="__init____3993"></a>三.<strong>init</strong>() 函数</h2> 
<p>上面的例子是最简单形式的类和对象&#xff0c;在现实生活应用程序中并没有真正有用。要理解类的含义&#xff0c;我们必须了解内置的 <strong>init</strong>() 函数。所有类都有一个名为 <strong>init</strong>() 的函数&#xff0c;它总是在类被初始化时执行。使用 <strong>init</strong>() 函数为对象属性赋值&#xff0c;或在创建对象时需要执行的其他操作。</p> 
<p>例如创建一个名为 Person 的类&#xff0c;使用 <strong>init</strong>() 函数为 name 和 age 赋值&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    self<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">.</span>name<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">.</span>age<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/222d6731d2e1404db935a059a745d015.png" alt="在这里插入图片描述" /><br /> 注意&#xff1a;<strong>init</strong>()每次使用该类创建新对象时都会自动调用该函数。</p> 
<h2><a id="_4012"></a>四.对象方法</h2> 
<p>让我们在 Person 类中创建一个方法。<br /> 例如插入一个打印问候语的函数&#xff0c;并在 p1 对象上执行它&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    self<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

  def <span class="token function">myfunc</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;我的名字是 &#34;</span> <span class="token operator">&#43;</span> self<span class="token punctuation">.</span>name<span class="token punctuation">)</span>

p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
p1<span class="token punctuation">.</span><span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f5a4e9033b654570831271514f0b9bc4.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4030"></a>五.自参数</h2> 
<p>self参数是对类当前实例的引用&#xff0c;用于访问属于该类的变量。它不必命名self&#xff0c;您可以随意调用它&#xff0c;但它必须是类中任何函数的第一个参数&#xff1a;</p> 
<pre><code class="prism language-c">lass Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>mysillyobject<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    mysillyobject<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    mysillyobject<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

  def <span class="token function">myfunc</span><span class="token punctuation">(</span>abc<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;我的名字是 &#34;</span> <span class="token operator">&#43;</span> abc<span class="token punctuation">.</span>name<span class="token punctuation">)</span>

p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
p1<span class="token punctuation">.</span><span class="token function">myfunc</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>跟使用self效果一样<br /> <img src="https://img-blog.csdnimg.cn/f139a3ff4103428f8a1540de2a16fa80.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4047"></a>六.对象及其属性更改</h2> 
<p><strong>替换</strong><br /> 例如修改年龄为21</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>mysillyobject<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    mysillyobject<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    mysillyobject<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

  def <span class="token function">myfunc</span><span class="token punctuation">(</span>abc<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;我的名字是 &#34;</span> <span class="token operator">&#43;</span> abc<span class="token punctuation">.</span>name<span class="token punctuation">)</span>

p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;川川菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span>
p1<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> <span class="token number">21</span>
<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">.</span>age<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/c334df98e42a4f62b4f3d303c988c7ea.png" alt="在这里插入图片描述" /><br /> <strong>删除对象属性</strong><br /> 例如从 p1 对象中删除 age 属性&#xff1a;</p> 
<pre><code class="prism language-c">lass Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    self<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

  def <span class="token function">myfunc</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello my name is &#34;</span> <span class="token operator">&#43;</span> self<span class="token punctuation">.</span>name<span class="token punctuation">)</span>
p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span> <span class="token number">36</span><span class="token punctuation">)</span>
del p1<span class="token punctuation">.</span>age
<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">.</span>age<span class="token punctuation">)</span>#没有了自然打印报错
</code></pre> 
<p><strong>删除对象</strong><br /> 比如删除对象p1</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> name<span class="token punctuation">,</span> age<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>name <span class="token operator">&#61;</span> name
    self<span class="token punctuation">.</span>age <span class="token operator">&#61;</span> age

  def <span class="token function">myfunc</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello my name is &#34;</span> <span class="token operator">&#43;</span> self<span class="token punctuation">.</span>name<span class="token punctuation">)</span>

p1 <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span> <span class="token number">36</span><span class="token punctuation">)</span>

del p1

<span class="token function">print</span><span class="token punctuation">(</span>p1<span class="token punctuation">)</span>#对象都不在了肯定报错
</code></pre> 
<h2><a id="pass_4098"></a>七.pass语句</h2> 
<p>class定义不能为空&#xff0c;但如果您出于某种原因有一个class没有内容的定义&#xff0c;请放入pass语句中以避免出错。</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  pass
</code></pre> 
<h1><a id="Python_4105"></a>三十、Python继承</h1> 
<p><img src="https://img-blog.csdnimg.cn/56d63f3a4e3a46e79e29c6e285d02fb2.png" alt="在这里插入图片描述" /></p> 
<p>继承允许我们定义一个从另一个类继承所有方法和属性的类。父类是被继承的类&#xff0c;也称为基类。子类是从另一个类继承的类&#xff0c;也称为派生类。</p> 
<h2><a id="_4111"></a>一.创建父类</h2> 
<p>任何类都可以是父类&#xff0c;因此语法与创建任何其他类相同&#xff1a;<br /> 这里创建一个名为Person、 firstname和lastname属性的类&#xff0c;以及一个printname方法&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>


x <span class="token operator">&#61;</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
x<span class="token punctuation">.</span><span class="token function">printname</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a6226e395309488eb6aefae01d3de4e0.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4130"></a>二.创建子类</h2> 
<p>创建从另一个类继承功能的类&#xff0c;请在创建子类时将父类作为参数发送。<br /> 例如&#xff1a;创建一个名为 的类Student&#xff0c;它将继承该类的属性和方法Person</p> 
<pre><code class="prism language-c">class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  pass
</code></pre> 
<p><strong>注意&#xff1a;</strong> pass 当您不想向类添加任何其他属性或方法时&#xff0c;请使用关键字。<br /> 现在 Student 类具有与 Person 类相同的属性和方法。使用Student类创建对象&#xff0c;然后执行printname方法&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  pass

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
x<span class="token punctuation">.</span><span class="token function">printname</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre> 
<p>返回还是一样<br /> <img src="https://img-blog.csdnimg.cn/f483366149444ce8b977e7d16e24dbad.png" alt="在这里插入图片描述" /></p> 
<h2><a id="___init____4160"></a>三.添加 <strong>init</strong>() 函数</h2> 
<p>到目前为止&#xff0c;我们已经创建了一个继承父类的属性和方法的子类。我们想将__init__()函数添加到子类&#xff08;而不是pass关键字&#xff09;。<br /> <strong>注意</strong>&#xff1a;<strong>init</strong>()每次使用该类创建新对象时都会自动调用该函数。<br /> 例如&#xff1a;将__init__()函数添加到 Student类中</p> 
<pre><code class="prism language-c">class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
</code></pre> 
<p>添加__init__()函数后&#xff0c;子类将不再继承父类的__init__()函数。注&#xff1a;孩子的__init__() 功能覆盖父母的继承 <strong>init</strong>()功能。为了保持父__init__() 函数的继承&#xff0c;添加对父函数的调用__init__()&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    Person<span class="token punctuation">.</span><span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span>

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
x<span class="token punctuation">.</span><span class="token function">printname</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>这样效果一样&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/99ab2e59900340ff963ab35c8291d49e.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_super__4190"></a>四.使用 super() 函数</h2> 
<p>Python 还有一个super()函数可以让子类继承其父类的所有方法和属性&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">__init__</span><span class="token punctuation">(</span>fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span>

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
x<span class="token punctuation">.</span><span class="token function">printname</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>一样返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/385cd39d9b0b487e8792105a1f03056e.png" alt="在这里插入图片描述" /><br /> 通过使用该super()函数&#xff0c;您不必使用父元素的名称&#xff0c;它会自动从其父元素继承方法和属性。</p> 
<h2><a id="_4213"></a>五.添加属性</h2> 
<p>添加一个属性调用graduationyear到 Student类&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">__init__</span><span class="token punctuation">(</span>fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span>
    self<span class="token punctuation">.</span>graduationyear <span class="token operator">&#61;</span> <span class="token number">2021</span>

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span>graduationyear<span class="token punctuation">)</span>

</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/662b6ca490c04e02a3c147119dd413ea.png" alt="在这里插入图片描述" /><br /> 年份2019应该是一个变量&#xff0c;并Student在创建学生对象时传递给 类。为此&#xff0c;请在 <strong>init</strong>() 函数中添加另一个参数。<br /> 添加year参数&#xff0c;并在创建对象时传递正确的年份&#xff1a;</p> 
<pre><code class="prism language-c">class Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">,</span> year<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">__init__</span><span class="token punctuation">(</span>fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span>
    self<span class="token punctuation">.</span>graduationyear <span class="token operator">&#61;</span> year

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">2021</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span>graduationyear<span class="token punctuation">)</span>
</code></pre> 
<p>返回一样为2021</p> 
<h2><a id="_4257"></a>六.添加方法</h2> 
<p>添加一个调用welcome到 Student类的方法&#xff1a;</p> 
<pre><code class="prism language-c">lass Person<span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span><span class="token operator">:</span>
    self<span class="token punctuation">.</span>firstname <span class="token operator">&#61;</span> fname
    self<span class="token punctuation">.</span>lastname <span class="token operator">&#61;</span> lname

  def <span class="token function">printname</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">)</span>

class <span class="token function">Student</span><span class="token punctuation">(</span>Person<span class="token punctuation">)</span><span class="token operator">:</span>
  def <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> fname<span class="token punctuation">,</span> lname<span class="token punctuation">,</span> year<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">__init__</span><span class="token punctuation">(</span>fname<span class="token punctuation">,</span> lname<span class="token punctuation">)</span>
    self<span class="token punctuation">.</span>graduationyear <span class="token operator">&#61;</span> year

  def <span class="token function">welcome</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token operator">:</span>
    <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Welcome&#34;</span><span class="token punctuation">,</span> self<span class="token punctuation">.</span>firstname<span class="token punctuation">,</span> self<span class="token punctuation">.</span>lastname<span class="token punctuation">,</span> <span class="token string">&#34;to the class of&#34;</span><span class="token punctuation">,</span> self<span class="token punctuation">.</span>graduationyear<span class="token punctuation">)</span>

x <span class="token operator">&#61;</span> <span class="token function">Student</span><span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span><span class="token punctuation">,</span> <span class="token string">&#34;菜鸟&#34;</span><span class="token punctuation">,</span> <span class="token number">2021</span><span class="token punctuation">)</span>
x<span class="token punctuation">.</span><span class="token function">welcome</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回<br /> <img src="https://img-blog.csdnimg.cn/66f484fda4fe4a9ea10a09d4f05b2553.png" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_4282"></a>三十一、Python日期</h1> 
<p><img src="https://img-blog.csdnimg.cn/964813b8c6ad4e7cb1eded9f96f5c76b.png" alt="在这里插入图片描述" /></p> 
<p>Python 中的日期不是它自己的数据类型&#xff0c;但我们可以导入一个名为的模块datetime来处理日期作为日期对象。</p> 
<h2><a id="_4286"></a>一.日期输入输出</h2> 
<p>导入 datetime 模块并显示<strong>当前日期</strong>&#xff1a;</p> 
<pre><code class="prism language-c">import datetime

x <span class="token operator">&#61;</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/bde824aaebb54da986d2ff211aa05a48.png" alt="在这里插入图片描述" /><br /> <strong>日期输出</strong><br /> 当我们执行上面示例中的代码时&#xff0c;结果将是&#xff1a;2021-08-25 05:36:01.704218<br /> 日期包含年、月、日、小时、分钟、秒和微秒。</p> 
<p>回工作日的年份和名称&#xff1a;</p> 
<pre><code class="prism language-c">import datetime

x <span class="token operator">&#61;</span> datetime<span class="token punctuation">.</span>datetime<span class="token punctuation">.</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span>year<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span><span class="token function">strftime</span><span class="token punctuation">(</span><span class="token string">&#34;%A&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e13bde5ef431411f8aac67a4caa8d53f.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4313"></a>二.创建日期对象</h2> 
<p>要创建日期&#xff0c;我们可以使用模块的datetime()类&#xff08;构造函数&#xff09; datetime。本datetime()类需要三个参数来创建日期&#xff1a;年&#xff0c;月&#xff0c;日。</p> 
<pre><code class="prism language-c">import datetime

x <span class="token operator">&#61;</span> datetime<span class="token punctuation">.</span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token number">2021</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">)</span>

<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回<br /> <img src="https://img-blog.csdnimg.cn/e1e7d9e8a0b84fd9a056cad61f069521.png" alt="在这里插入图片描述" /></p> 
<p>datetime()类也需要参数的时间和时区&#xff08;小时&#xff0c;分钟&#xff0c;秒&#xff0c;微秒&#xff0c;tzone&#xff09;&#xff0c;但它们是可选的&#xff0c;并且具有一个默认值0&#xff0c;&#xff08;None对时区&#xff09;。</p> 
<h2><a id="strftime__4328"></a>三.strftime() 方法</h2> 
<p>该datetime对象具有将日期对象格式化为可读字符串的方法。该方法被调用strftime()&#xff0c;并采用一个参数 format&#xff0c;来指定返回字符串的格式。<br /> 例如显示月份名称&#xff1a;</p> 
<pre><code class="prism language-c">import datetime
x <span class="token operator">&#61;</span> datetime<span class="token punctuation">.</span><span class="token function">datetime</span><span class="token punctuation">(</span><span class="token number">2011</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">25</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">.</span><span class="token function">strftime</span><span class="token punctuation">(</span><span class="token string">&#34;%B&#34;</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回<br /> <img src="https://img-blog.csdnimg.cn/8eec8d0ace7b41fba97a5e40e6251ce4.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4339"></a>四.其它调用方法</h2> 
<p>实在太多&#xff0c;不能一一演示&#xff0c;大家自己看下。<br /> <img src="https://img-blog.csdnimg.cn/0c6f641c3f51488d95862cd45b16efde.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<p><img src="https://img-blog.csdnimg.cn/ce5fa6ebdada4e11812337f5e5311c08.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_36,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /><br /> <img src="https://img-blog.csdnimg.cn/3d60a5b8038e41408847abad07ab82bb.png?x-oss-process&#61;image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_Q1NETiBA5bed5bed6I-c6bif,size_37,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述" /></p> 
<h1><a id="Python_JSON_4345"></a>三十二、Python JSON</h1> 
<p>JSON 是一种用于存储和交换数据的语法。JSON 是文本&#xff0c;用 JavaScript 对象表示法编写。<br /> Python 有一个名为 的内置包json&#xff0c;可用于处理 JSON 数据。<br /> 导入 json 模块&#xff1a;</p> 
<pre><code class="prism language-c">import json
</code></pre> 
<h2><a id="_JSON__Python_4352"></a>一.从 JSON 转换为 Python</h2> 
<p>如果您有 JSON 字符串&#xff0c;则可以使用json.loads()方法对其进行解析 。<br /> 结果将是一个Python 字典。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">import json
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">some</span> <span class="token expression">JSON<span class="token operator">:</span></span></span>
x <span class="token operator">&#61;</span><span class="token string">&#39;{ &#34;name&#34;:&#34;川川&#34;, &#34;age&#34;:20, &#34;city&#34;:&#34;上海&#34;}&#39;</span>

# 解析x
y <span class="token operator">&#61;</span> json<span class="token punctuation">.</span><span class="token function">loads</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
#会返回字典
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">[</span><span class="token string">&#34;age&#34;</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/76bc4a2200c547878844af2daab4cada.png" alt="在这里插入图片描述" /></p> 
<p>如果您有 Python 对象&#xff0c;则可以使用json.dumps()方法将其转换为 JSON 字符串。</p> 
<pre><code class="prism language-c">import json
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">x</span><span class="token expression">为字典</span></span>
x <span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span>
  <span class="token string">&#34;name&#34;</span><span class="token operator">:</span> <span class="token string">&#34;John&#34;</span><span class="token punctuation">,</span>
  <span class="token string">&#34;age&#34;</span><span class="token operator">:</span> <span class="token number">30</span><span class="token punctuation">,</span>
  <span class="token string">&#34;city&#34;</span><span class="token operator">:</span> <span class="token string">&#34;New York&#34;</span>
<span class="token punctuation">}</span>
# 转为json
y <span class="token operator">&#61;</span> json<span class="token punctuation">.</span><span class="token function">dumps</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
# 结果为json字符串
<span class="token function">print</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token function">type</span><span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回为<br /> <img src="https://img-blog.csdnimg.cn/0c197483e6db42d9b0c2664fcb213f28.png" alt="在这里插入图片描述" /></p> 
<h1><a id="_4387"></a>三十三、异常处理</h1> 
<p><img src="https://img-blog.csdnimg.cn/4ed28697c08c4e39bf171bc0b3df72a5.png" alt="在这里插入图片描述" /></p> 
<p>try块可让您测试代码块的错误。except块可让您处理错误。finally无论 try- 和 except 块的结果如何&#xff0c;该块都允许您执行代码。</p> 
<h2><a id="_4392"></a>一.异常处理</h2> 
<p>例如该try块将产生异常&#xff0c;因为x未定义&#xff1a;</p> 
<pre><code class="prism language-c">try<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
except<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;An exception occurred&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回<img src="https://img-blog.csdnimg.cn/909001a9594b4d76b453752ca2e6b6c8.png" alt="在这里插入图片描述" /></p> 
<p>由于 try 块引发错误&#xff0c;因此将执行 except 块。如果没有 try 块&#xff0c;程序将崩溃并引发错误。</p> 
<h2><a id="else_4404"></a>二.else搭配</h2> 
<p>else如果没有出现错误&#xff0c;您可以使用关键字来定义要执行的代码块&#xff1a;</p> 
<pre><code class="prism language-c">try<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Hello&#34;</span><span class="token punctuation">)</span>
except<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Something went wrong&#34;</span><span class="token punctuation">)</span>
<span class="token keyword">else</span><span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Nothing went wrong&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/fac6e6ffce6845f09a1aae4d4dae17ac.png" alt="在这里插入图片描述" /></p> 
<h2><a id="finally_4417"></a>三.finally语句</h2> 
<p>finally如果指定了该块&#xff0c;则无论 try 块是否引发错误&#xff0c;都将执行该块。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">try<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
except<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Something went wrong&#34;</span><span class="token punctuation">)</span>
finally<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;The &#39;try except&#39; is finished&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a68dbd8098544a6da2aa5eb4b0fb66f8.png" alt="在这里插入图片描述" /><br /> 这对于关闭对象和清理资源很有用。<br /> 例如尝试打开并写入不可写的文件&#xff1a;</p> 
<pre><code class="prism language-c">try<span class="token operator">:</span>
  f <span class="token operator">&#61;</span> <span class="token function">open</span><span class="token punctuation">(</span><span class="token string">&#34;demofile.txt&#34;</span><span class="token punctuation">)</span>
  f<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&#34;Lorum Ipsum&#34;</span><span class="token punctuation">)</span>
except<span class="token operator">:</span>
  <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;Something went wrong when writing to the file&#34;</span><span class="token punctuation">)</span>
finally<span class="token operator">:</span>
  f<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
<p>程序可以继续&#xff0c;而无需打开文件对象。</p> 
<h2><a id="_4444"></a>四.引发异常</h2> 
<p>要抛出&#xff08;或引发&#xff09;异常&#xff0c;请使用raise关键字。<br /> 例如如果 x 小于 0&#xff0c;则引发错误并停止程序&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token operator">-</span><span class="token number">1</span>

<span class="token keyword">if</span> x <span class="token operator">&lt;</span> <span class="token number">0</span><span class="token operator">:</span>
  raise <span class="token function">Exception</span><span class="token punctuation">(</span><span class="token string">&#34;Sorry, no numbers below zero&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/02540f4401c14b2cb5673c79a215bb12.png" alt="在这里插入图片描述" /><br /> 该raise关键字用于引发异常。您可以定义要引发的错误类型以及要打印给用户的文本。<br /> 例如如果 x 不是整数&#xff0c;则引发 TypeError&#xff1a;</p> 
<pre><code class="prism language-c">x <span class="token operator">&#61;</span> <span class="token string">&#34;hello&#34;</span>

<span class="token keyword">if</span> not <span class="token function">type</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> is <span class="token keyword">int</span><span class="token operator">:</span>
  raise <span class="token function">TypeError</span><span class="token punctuation">(</span><span class="token string">&#34;Only integers are allowed&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回<br /> <img src="https://img-blog.csdnimg.cn/25e0e84376354789a145dc37e276b76d.png" alt="在这里插入图片描述" /></p> 
<h1><a id="_4467"></a>三十四、用户输入</h1> 
<p><img src="https://img-blog.csdnimg.cn/4e7b2965237344ee9c09df1da58f2107.png" alt="在这里插入图片描述" /></p> 
<p>实在太简单了&#xff0c;就是使用一个input(),将输入后的值传递给另一个变量&#xff0c;相当于动态赋值、<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-c">username <span class="token operator">&#61;</span> <span class="token function">input</span><span class="token punctuation">(</span><span class="token string">&#34;你叫什么名字:&#34;</span><span class="token punctuation">)</span>
<span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&#34;名字叫: &#34;</span> <span class="token operator">&#43;</span> username<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/ffaa0dfb0ab64d0ca2e638f98eabfb8d.png" alt="在这里插入图片描述" /></p> 
<h1><a id="_4479"></a>三十五.格式化输入输出</h1> 
<p>讲解在注释里面。</p> 
<pre><code class="prism language-c"><span class="token string">&#39;&#39;</span><span class="token string">&#39;在字符串开头的引号/三引号前添加 f 或 F 。在这种字符串中&#xff0c;可以在 { 和 } 字符之间输入引用的变量&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">year</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token number">2021</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">event</span> <span class="token expression"><span class="token operator">&#61;</span> </span><span class="token string">&#39;Referendum&#39;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span>f</span><span class="token string">&#39;Results of the {year} {event}&#39;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;str.format() 该方法也用 { 和 } 标记替换变量的位置a  这种方法支持详细的格式化指令&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">yes</span><span class="token expression">_votes <span class="token operator">&#61;</span> <span class="token number">42</span>_572_654</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">no</span><span class="token expression">_votes <span class="token operator">&#61;</span> <span class="token number">43</span>_132_495</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">percentage</span> <span class="token expression"><span class="token operator">&#61;</span> yes_votes <span class="token operator">/</span> <span class="token punctuation">(</span>yes_votes <span class="token operator">&#43;</span> no_votes<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span></span><span class="token string">&#39;{:-5} YES votes  {:1.1%}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>yes_votes<span class="token punctuation">,</span> percentage<span class="token punctuation">)</span>#调整<span class="token punctuation">{<!-- --></span><span class="token punctuation">}</span>内部感受下</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">)</span></span></span>


<span class="token string">&#39;&#39;</span><span class="token string">&#39;只想快速显示变量进行调试&#xff0c;可以用 repr() 或 str() 函数把值转化为字符串。&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">s</span> <span class="token expression"><span class="token operator">&#61;</span> </span><span class="token string">&#39;Hello, world.&#39;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span><span class="token function">str</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">)</span>#<span class="token function">str</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 函数返回供人阅读的值</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span><span class="token function">repr</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">)</span>#<span class="token function">repr</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 则生成适于解释器读取的值</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span><span class="token function">str</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">/</span><span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">hellos</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token function">repr</span><span class="token punctuation">(</span></span><span class="token string">&#39;hello&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>hellos<span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.1.1. 格式化字符串字面值&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;格式化字符串字面值 &#xff08;简称为 f-字符串&#xff09;在字符串前加前缀 f 或 F&#xff0c;通过 {expression} 表达式&#xff0c;把 Python 表达式的值添加到字符串内&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;下例将 pi 舍入到小数点后三位&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">import</span> <span class="token expression">math</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>f</span><span class="token string">&#39;The value of pi is approximately {math.pi:.3f}.&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;在 &#39;</span><span class="token operator">:</span><span class="token string">&#39; 后传递整数&#xff0c;为该字段设置最小字符宽度&#xff0c;常用于列对齐&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">table</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span></span><span class="token string">&#39;Sjoerd&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">4127</span><span class="token punctuation">,</span> </span><span class="token string">&#39;Jack&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">4098</span><span class="token punctuation">,</span> </span><span class="token string">&#39;Dcab&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">7678</span><span class="token punctuation">}</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">for</span> <span class="token expression">name<span class="token punctuation">,</span> phone in table<span class="token punctuation">.</span><span class="token function">items</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>f</span><span class="token string">&#39;{name:10} &#61;&#61;&gt; {phone:10d}&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>


<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.1.2. 字符串 format() 方法&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;We are the {} who say &#34;{}!&#34;&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span></span><span class="token string">&#39;knights&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;Ni&#39;</span><span class="token expression"><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;花括号及之内的字符&#xff08;称为格式字段&#xff09;被替换为传递给 str.format() 方法的对象。花括号中的数字表示传递给 str.format() 方法的对象所在的位置。&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;{0} and {1}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span></span><span class="token string">&#39;spam&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;eggs&#39;</span><span class="token expression"><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;{1} and {0}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span></span><span class="token string">&#39;spam&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;eggs&#39;</span><span class="token expression"><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;使用关键字参数名引用值。&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;This {food} is {adjective}.&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>food<span class="token operator">&#61;</span></span><span class="token string">&#39;spam&#39;</span><span class="token expression"><span class="token punctuation">,</span> adjective<span class="token operator">&#61;</span></span><span class="token string">&#39;absolutely horrible&#39;</span><span class="token expression"><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;位置参数和关键字参数可以任意组合&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;The story of {0}, {1}, and {other}.&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span></span><span class="token string">&#39;Bill&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;Manfred&#39;</span><span class="token expression"><span class="token punctuation">,</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>                                                        <span class="token directive keyword">other</span><span class="token expression"><span class="token operator">&#61;</span></span><span class="token string">&#39;Georg&#39;</span><span class="token expression"><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;用方括号 &#39;</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token string">&#39; 访问键来完成&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">table</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token punctuation">{<!-- --></span></span><span class="token string">&#39;Sjoerd&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">4127</span><span class="token punctuation">,</span> </span><span class="token string">&#39;Jack&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">4098</span><span class="token punctuation">,</span> </span><span class="token string">&#39;Dcab&#39;</span><span class="token expression"><span class="token operator">:</span> <span class="token number">8637678</span><span class="token punctuation">}</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; &#39;</span><span class="token string">&#39;Dcab: {0[Dcab]:d}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>table<span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;也可以用 &#39;</span><span class="token operator">*</span><span class="token operator">*</span><span class="token string">&#39; 符号&#xff0c;把 table 当作传递的关键字参数。&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token operator">*</span>table<span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;生成一组整齐的列&#xff0c;包含给定整数及其平方与立方&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">for</span> <span class="token expression">x in <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span><span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;{0:2d} {1:3d} {2:4d}&#39;</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> x <span class="token operator">*</span> x<span class="token punctuation">,</span> x <span class="token operator">*</span> x <span class="token operator">*</span> x<span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>


<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.1.3. 手动格式化字符串&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">for</span> <span class="token expression">x in <span class="token function">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">)</span><span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span><span class="token function">repr</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">rjust</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">repr</span><span class="token punctuation">(</span>x <span class="token operator">*</span> x<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">rjust</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> end<span class="token operator">&#61;</span></span><span class="token string">&#39; &#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span><span class="token function">repr</span><span class="token punctuation">(</span>x <span class="token operator">*</span> x <span class="token operator">*</span> x<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">rjust</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.1.4. 旧式字符串格式化方法&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">import</span> <span class="token expression">math</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span></span><span class="token string">&#39;The value of pi is approximately %5.3f.&#39;</span> <span class="token expression"><span class="token operator">%</span> math<span class="token punctuation">.</span>pi<span class="token punctuation">)</span></span></span>


<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.2. 读写文件¶&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;最常用的参数有两个: open(filename, mode)&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;w&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span>&#39;
第一个实参是文件名字符串第二个实参是包含描述文件使用方式字符的字符串。
mode 的值包括 <span class="token string">&#39;r&#39;</span> &#xff0c;表示文件只能读取&#xff1b;<span class="token string">&#39;w&#39;</span> 表示只能写入&#xff08;现有同名文件会被覆盖&#xff09;&#xff1b;
<span class="token string">&#39;a&#39;</span> 表示打开文件并追加内容&#xff0c;任何写入的数据会自动添加到文件末尾。<span class="token string">&#39;r&#43;&#39;</span> 表示打开文件进行读写。
mode 实参是可选的&#xff0c;省略时的默认值为 <span class="token string">&#39;r&#39;</span>。
<span class="token string">&#39;&#39;</span>&#39;
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">read</span><span class="token expression">_data <span class="token operator">&#61;</span> f<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>read_data<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span>#如果没有使用 with 关键字&#xff0c;则应调用 f<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 关闭文件&#xff0c;即可释放文件占用的系统资源。</span></span>

<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span>f<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;f.readline() 从文件中读取单行数据&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span>f<span class="token punctuation">.</span><span class="token function">readline</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">b</span><span class="token expression"><span class="token operator">&#61;</span>f<span class="token punctuation">.</span><span class="token function">readline</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">c</span><span class="token expression"><span class="token operator">&#61;</span>f<span class="token punctuation">.</span><span class="token function">readline</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">)</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">for</span> <span class="token expression">i in f<span class="token operator">:</span></span></span>
   <span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>i<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;从文件中读取多行时&#xff0c;可以用循环遍历整个文件对象&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">for</span> <span class="token expression">line in f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>         <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>line<span class="token punctuation">,</span> end<span class="token operator">&#61;</span></span><span class="token string">&#39;&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;f.write(string) 把 string 的内容写入文件&#xff0c;并返回写入的字符数。&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">,</span></span><span class="token string">&#39;w&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span></span><span class="token string">&#39;This is a test\n&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;写入其他类型的对象前&#xff0c;要先把它们转化为字符串&#xff08;文本模式&#xff09;或字节对象&#xff08;二进制模式&#xff09;&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">with</span> <span class="token expression"><span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">,</span></span><span class="token string">&#39;a&#39;</span><span class="token expression"><span class="token punctuation">)</span> as f<span class="token operator">:</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">value</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token punctuation">(</span></span><span class="token string">&#39;the answer&#39;</span><span class="token expression"><span class="token punctuation">,</span> <span class="token number">42</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">s</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token function">str</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span>     <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span></span>

<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span> <span class="token expression"><span class="token operator">&#61;</span> <span class="token function">open</span><span class="token punctuation">(</span></span><span class="token string">&#39;workfile&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;rb&#43;&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">f</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>b</span><span class="token string">&#39;0123456789abcdef&#39;</span><span class="token expression"><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>f<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>f<span class="token punctuation">.</span><span class="token function">seek</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>f<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>

<span class="token string">&#39;&#39;</span><span class="token string">&#39;7.2.2. 使用 json 保存结构化数据&#39;</span><span class="token string">&#39;&#39;</span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">import</span> <span class="token expression">json</span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">a</span><span class="token expression"><span class="token operator">&#61;</span>json<span class="token punctuation">.</span><span class="token function">dumps</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> </span><span class="token string">&#39;simple&#39;</span><span class="token expression"><span class="token punctuation">,</span> </span><span class="token string">&#39;list&#39;</span><span class="token expression"><span class="token punctuation">]</span><span class="token punctuation">)</span></span></span>
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">print</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">)</span></span></span>
<span class="token string">&#39;&#39;</span><span class="token string">&#39;dumps() 函数还有一个变体&#xff0c; dump() &#xff0c;它只将对象序列化为 text file &#39;</span><span class="token string">&#39;&#39;</span>
#如果 f 是 text file 对象
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">json</span><span class="token expression"><span class="token punctuation">.</span><span class="token function">dump</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> f<span class="token punctuation">)</span></span></span>
#要再次解码对象&#xff0c;如果 f 是已打开、供读取的 text file 对象
<span class="token macro property"><span class="token directive-hash">#</span> <span class="token directive keyword">x</span> <span class="token expression"><span class="token operator">&#61;</span> json<span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span>f<span class="token punctuation">)</span></span></span>
© <span class="token number">2021</span> GitHub<span class="token punctuation">,</span> Inc<span class="token punctuation">.</span>
</code></pre> 
<h1><a id="python_4611"></a>三十六、python正则表达式</h1> 
<p><img src="https://img-blog.csdnimg.cn/145c7acb998941f1bce47dc4bf237e25.png" alt="在这里插入图片描述" /></p> 
<p>Python 有一个名为 的内置包re&#xff0c;可用于处理正则表达式。导入re模块&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re
</code></pre> 
<h2><a id="Python_4619"></a>一.Python中的正则表达式</h2> 
<p>导入re模块后&#xff0c;您可以开始使用正则表达式。<br /> 例如&#xff1a;搜索字符串以查看它是否以“The”开头并以“Spain”结尾&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;The rain in Spain&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span><span class="token string">&#34;^The.*Spain$&#34;</span>, txt<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配成功!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配失败&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a2db0d0e067f4a52bf4423fd870d7fb4.png" alt="在这里插入图片描述" /><br /> 当然&#xff0c;你现在看不懂这个例子&#xff0c;既然手把手教学&#xff0c;并不会教大家一步登天。</p> 
<h2><a id="_4637"></a>二.正则表达式函数</h2> 
<h3><a id="21_findall__4638"></a>2.1 findall() 函数</h3> 
<p>该findall()函数返回一个包含所有匹配项的列表。<br /> 例如&#xff1a;打印所有匹配项的列表</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川菜鸟啊菜鸟啊&#34;</span>
x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;菜鸟&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/f2468192917944d5a7ba647e06069628.png" alt="在这里插入图片描述" /><br /> 该列表按找到的顺序包含匹配项。如果未找到匹配项&#xff0c;则返回一个空列表&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟并不菜&#34;</span>


x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span>x<span class="token punctuation">)</span>:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配成功了哟&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;找不到这个呀&#xff01;&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a99638d593934fa7a80c4e022c55bdc2.png" alt="在这里插入图片描述" /></p> 
<h3><a id="22search__4669"></a>2.2search() 函数</h3> 
<p>该search()函数在字符串中搜索匹配项&#xff0c;如果有匹配项&#xff0c;则返回一个Match 对象。如果有多个匹配项&#xff0c;则只返回匹配项的<strong>第一次</strong>出现。<br /> 例如&#xff1a;搜索字符串中的第一个空白字符&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟 呢&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span><span class="token string">&#34;\s&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span><span class="token string">&#34;第一个空格字符位于位置:&#34;</span>, x.start<span class="token punctuation">(</span><span class="token punctuation">))</span> 
</code></pre> 
<p>运行结果&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6769f062e07c41e3a9c7f33334d46405.png" alt="在这里插入图片描述" /><br /> 如果未找到匹配项&#xff0c;None则返回该值&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;天上飞的是菜鸟&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span><span class="token string">&#34;川川&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/0a7244306a044e71b1b97460ced22fc9.png" alt="在这里插入图片描述" /></p> 
<h3><a id="23_split__4694"></a>2.3 split() 函数</h3> 
<p>该split()函数返回一个列表&#xff0c;其中的字符串在每次匹配时被拆分。<br /> 例如&#xff1a;在每个空白字符处拆分</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟 学 python&#34;</span>
x <span class="token operator">&#61;</span> re.split<span class="token punctuation">(</span><span class="token string">&#34;\s&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/6bf8bba62784466cb11d49ac986348e6.png" alt="在这里插入图片描述" /><br /> 您可以通过指定maxsplit 参数来控制出现次数<br /> 例如&#xff1a;仅在第一次出现时拆分字符串&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

<span class="token comment">#Split the string at the first white-space character:</span>

txt <span class="token operator">&#61;</span> <span class="token string">&#34;飞起来 菜鸟 们&#34;</span>
x <span class="token operator">&#61;</span> re.split<span class="token punctuation">(</span><span class="token string">&#34;\s&#34;</span>, txt, <span class="token number">1</span><span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/32276a8da0194c2ab07452e3cc174d93.png" alt="在这里插入图片描述" /></p> 
<h3><a id="24_sub__4721"></a>2.4 sub() 函数</h3> 
<p>该sub()函数用您选择的文本替换匹配项。<br /> 例如&#xff1a;用只替换就</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;学python就找川川菜鸟&#34;</span>
x <span class="token operator">&#61;</span> re.sub<span class="token punctuation">(</span><span class="token string">&#34;就&#34;</span>, <span class="token string">&#34;只&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/445a0bb3f42245879430664456a3507d.png" alt="在这里插入图片描述" /><br /> 您可以通过指定count 参数来控制替换次数 &#xff1a;<br /> 例如替换前 2 次出现&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;学python就就就川川菜鸟&#34;</span>
x <span class="token operator">&#61;</span> re.sub<span class="token punctuation">(</span><span class="token string">&#34;就&#34;</span>, <span class="token string">&#34;只&#34;</span>, txt,2<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/9b879013debb4606a54e03167cfe103b.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4746"></a>三.元字符</h2> 
<p><img src="https://img-blog.csdnimg.cn/86d7e7b98ac846a1bbb1de061e730761.png" alt="在这里插入图片描述" /></p> 
<h3><a id="31__4749"></a>3.1 列表符号</h3> 
<p><strong>[]</strong> 用于一组字符<br /> 例如&#xff1a;#按字母顺序查找“a”和“m”之间的所有小写字符</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;apple chuanchuan &#34;</span>

<span class="token comment">#按字母顺序查找“a”和“m”之间的所有小写字符</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;[a-m]&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/5e86503d90794f43a870483f974ab00c.png" alt="在这里插入图片描述" /></p> 
<h3><a id="32_4764"></a>3.2转义符</h3> 
<p>*<em>*</em> 表示特殊序列&#xff08;也可用于转义特殊字符&#xff09;<br /> 例如匹配所有数字&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;我今年20岁了&#34;</span>

<span class="token comment">#查找所有数字字符</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\d&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

</code></pre> 
<p>运行返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/fc1230042e3144db888e41bda7c949c3.png" alt="在这里插入图片描述" /></p> 
<h3><a id="34__4781"></a>3.4 任意符号</h3> 
<p><strong>.</strong> 可以任何字符&#xff08;换行符除外&#xff09;。<br /> 例如&#xff1a;搜索以“he”开头、后跟两个&#xff08;任意&#xff09;字符和一个“o”的序列</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;hello world&#34;</span>

<span class="token comment">#搜索以“he”开头、后跟两个&#xff08;任意&#xff09;字符和一个“o”的序列</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;he..o&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/fa9ca920e5b64f09bc6a00330bd5a0ed.png" alt="在这里插入图片描述" /></p> 
<h3><a id="35_4796"></a>3.5开始符</h3> 
<p>^符号用于匹配开始。</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川菜鸟 飞起来了&#34;</span>


x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;^川&#34;</span>, txt<span class="token punctuation">)</span>
<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;哇&#xff0c;我匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;哎呀&#xff0c;匹配不了啊&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8993cf45bc1c4a648bacbafd896f8ad6.png" alt="在这里插入图片描述" /></p> 
<h3><a id="36__4813"></a>3.6 结束符</h3> 
<p><strong>$</strong> 符号用于匹配结尾&#xff0c;例如&#xff1a;匹配字符串是否以“world”结尾</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;hello world&#34;</span>

<span class="token comment">#匹配字符串是否以“world”结尾</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;world$&#34;</span>, txt<span class="token punctuation">)</span>
<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配成功了耶&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到哦&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a73a46a0ef8443f9a65fde136c37b5d6.png" alt="在这里插入图片描述" /></p> 
<h3><a id="37__4831"></a>3.7 星号符</h3> 
<ul><li>星号符用于匹配零次或者多次出现。</li></ul> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;天上飞的是菜鸟&#xff0c;学python找川川菜鸟!&#34;</span>

<span class="token comment">#检查字符串是否包含“ai”后跟 0 个或多个“x”字符&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;菜鸟*&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;气死了&#xff0c;匹配不到啊&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/e1e08e3b7cbc4364a089e575a08586cf.png" alt="在这里插入图片描述" /></p> 
<h3><a id="38__4852"></a>3.8 加号符</h3> 
<p><strong>&#43;</strong> 用于匹配一次或者多次出现<br /> 例如&#xff1a;检查字符串是否包含“菜鸟”后跟 1 个或多个“菜鸟”字符&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;飞起来了&#xff0c;菜鸟们!&#34;</span>

<span class="token comment">#检查字符串是否包含“菜鸟”后跟 1 个或多个“菜鸟”字符&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;菜鸟&#43;&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;烦死了&#xff0c;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/d6046a7e5d2644f2bdb0c8e411353b3f.png" alt="在这里插入图片描述" /></p> 
<h3><a id="39_4875"></a>3.9集合符号</h3> 
<p><strong>{}</strong> 恰好指定的出现次数<br /> 例如&#xff1a;检查字符串是否包含“川”两个</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川菜鸟并不菜!&#34;</span>

<span class="token comment">#检查字符串是否包含“川”两个</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;川{2}&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了两次的川&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到啊&#xff0c;帅哥&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>返回&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/09da072b8d3948618466e2c397661995.png" alt="在这里插入图片描述" /></p> 
<h3><a id="310_4896"></a>3.10或符</h3> 
<p><strong>|</strong> 匹配两者任一<br /> 例如&#xff1a;匹配字符串菜鸟或者是我了</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟们学会python了吗&#xff1f;串串也是菜鸟啊!&#34;</span>



x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;菜鸟|是我了&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了哦&#xff01;&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配失败&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/cf1544609e604b85a44c377a879b3fca.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_4917"></a>四.特殊序列</h2> 
<p><img src="https://img-blog.csdnimg.cn/5f1b8766d10a4bf2b8b16c9eb73328f7.png" alt="在这里插入图片描述" /></p> 
<h3><a id="41__4920"></a>4.1 指定字符</h3> 
<p><strong>\A</strong> &#xff1a; 如果指定的字符位于字符串的<strong>开头</strong>&#xff0c;则返回匹配项。<br /> 例如&#xff1a;匹配以菜字符开头的字符</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟在这里&#34;</span>


x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\A菜&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;是的匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/20547e1ca43e49da8f3cf56d088aa765.png" alt="在这里插入图片描述" /></p> 
<h3><a id="42__4941"></a>4.2 指定开头结尾</h3> 
<p>\b 返回指定字符位于单词开头或结尾的匹配项 &#xff08;开头的“r”确保字符串被视为原始字符串&#xff09;。<br /> 例如&#xff1a;匹配爱开头</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;爱你&#xff0c;川川&#34;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span>r<span class="token string">&#34;<span class="token entity" title="\b">\b</span>爱&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/33ab69e4a7ce4054bf07f4dfd4d87272.png" alt="在这里插入图片描述" /><br /> 又例如&#xff1a;匹配川结尾</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;爱你&#xff0c;川川&#34;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span>r<span class="token string">&#34;川<span class="token entity" title="\b">\b</span>&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/56f346faf6d14a549ded379e0e581fde.png" alt="在这里插入图片描述" /></p> 
<h3><a id="43_4979"></a>4.3匹配中间字符</h3> 
<p><strong>\B</strong> 返回存在指定字符但不在单词开头&#xff08;或结尾&#xff09;的匹配项 &#xff08;开头的“r”确保字符串被视为“原始字符串”&#xff09;<br /> 比如我匹配菜鸟&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;我是菜鸟我是菜鸟啊&#34;</span>

<span class="token comment">#检查是否存在“ain”&#xff0c;但不是在单词的开头&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span>r<span class="token string">&#34;\菜鸟&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了嘛&#xff01;!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到哇&#xff01;&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/490af59b6fe240ffbc80e00b8bad2065.png" alt="在这里插入图片描述" /><br /> 但是你匹配结尾就会返回空&#xff0c;比如我匹配鸟&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川菜鸟&#34;</span>

<span class="token comment">#检查是否存在“鸟”&#xff0c;但不是在单词的末尾&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span>r<span class="token string">&#34;鸟\B&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了哦&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;找不到&#34;</span><span class="token punctuation">)</span>

</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/8671470534134fc3bdd912d6aa749671.png" alt="在这里插入图片描述" /></p> 
<h3><a id="44_5022"></a>4.4匹配数字</h3> 
<p><strong>\d</strong> 返回字符串包含数字&#xff08;0-9 之间的数字&#xff09;的匹配项。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;我今年20岁了啊&#34;</span>

<span class="token comment">#检查字符串是否包含任何位数&#xff08;0-9的数字&#xff09;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\d&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;哇哇哇&#xff0c;匹配到数字了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;找不到哦&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/c7725d1c39744051bf96804fa5afa1e7.png" alt="在这里插入图片描述" /></p> 
<h3><a id="45__5044"></a>4.5 匹配非数字</h3> 
<p><strong>\D</strong> 返回字符串不包含数字的匹配项<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;我今年20岁&#34;</span>

<span class="token comment">#匹配任何非数字符号</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\D&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了&#xff0c;开心!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#xff0c;生气&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b988dbbffb024b53a947234f855d0514.png" alt="在这里插入图片描述" /></p> 
<h3><a id="46__5066"></a>4.6 空格匹配</h3> 
<p>\s 返回一个匹配字符串包含空白空间字符的匹配项。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;我 是 川 川 菜 鸟&#34;</span>

<span class="token comment">#匹配任何空格字符</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\s&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到啊&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/c91de5b73f3b441eabf531ffcccc4c3c.png" alt="在这里插入图片描述" /></p> 
<h3><a id="47__5088"></a>4.7 匹配非空格</h3> 
<p><strong>\S</strong> 返回字符串不包含空格字符的匹配项</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟是  我  了&#34;</span>

<span class="token comment">#匹配任意非空字符</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\S&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到啊&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/4778c33ba0ba4ff5b3b0ca331c063d70.png" alt="在这里插入图片描述" /></p> 
<h3><a id="48__5109"></a>4.8 匹配任意数字和字母</h3> 
<p>返回一个匹配&#xff0c;其中字符串包含任何单词字符&#xff08;从 a 到 Z 的字符&#xff0c;从 0 到 9 的数字&#xff0c;以及下划线 _ 字符&#xff09;<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟啊 是串串呀&#34;</span>

<span class="token comment">#在每个单词字符&#xff08;从a到z的字符&#xff0c;0-9的数字&#xff09;返回匹配项&#xff0c;以及下划线_字符&#xff09;&#xff1a;</span>
x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\w&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了啊&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到哇&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/d79e26628a9a4df0abbd61b9d4118b26.png" alt="在这里插入图片描述" /></p> 
<h3><a id="49_5130"></a>4.9匹配任意非数字和字母</h3> 
<p>返回字符串不包含任何单词字符的匹配项&#xff0c;在每个非单词字符中返回匹配&#xff08;不在A和Z之间的字符。“&#xff01;”&#xff0c;“&#xff1f;”空白位等&#xff09;<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;菜鸟 是 我嘛&#xff1f;我不信&#xff01;&#xff01;&#34;</span>

<span class="token comment">#在每个非单词字符中返回匹配&#xff08;不在A和Z之间的字符。“&#xff01;”&#xff0c;“&#xff1f;”空白位等&#xff09;&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;\W&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到啊&#34;</span><span class="token punctuation">)</span>

</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/120410ac7bf4433ea6065945d3784430.png" alt="在这里插入图片描述" /></p> 
<h3><a id="410__5152"></a>4.10 匹配结尾</h3> 
<p>\Z 如果指定的字符位于字符串的末尾&#xff0c;则返回匹配项。<br /> 例如&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;川川是菜鸟啊&#34;</span>


x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;啊\Z&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了哦!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h2><a id="_5171"></a>五.集合套装</h2> 
<h3><a id="51__5172"></a>5.1 指定符范围匹配</h3> 
<p>例如集合&#xff1a;[arn]</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;The rain in Spain&#34;</span>


x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;[arn]&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<h3><a id="52__5189"></a>5.2 匹配任意范围内小写字母</h3> 
<p>返回任何小写字符的匹配项&#xff0c;按字母顺序在 a 和 n 之间。<br /> 例如:</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;hello wo r l d&#34;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;[a-n]&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了!&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/27963974db2e41c79c04975a2f38e8b6.png" alt="在这里插入图片描述" /></p> 
<h3><a id="53__5209"></a>5.3 其它</h3> 
<p>同样的道理&#xff0c;依次其它情况如下&#xff1a;</p> 
<p><strong>[^arn]</strong> 返回除 a、r 和 n 之外的任何字符的匹配项</p> 
<p><strong>[0123]</strong> 返回存在任何指定数字&#xff08;0、1、2 或 3&#xff09;的匹配项</p> 
<p><strong>[0-9]</strong> 返回 0 到 9 之间任意数字的匹配项</p> 
<p><strong>[0-5][0-9]</strong> 返回 00 到 59 中任意两位数的匹配项</p> 
<p><strong>[a-zA-Z]</strong> 按字母顺序返回 a 和 z 之间的任何字符的匹配&#xff0c;小写或大写</p> 
<p><strong>[&#43;]</strong> 在集合中&#xff0c;&#43;, *, ., |, (), $,{} 没有特殊含义&#xff0c;所以 [&#43;] 的意思是&#xff1a;返回字符串中任意 &#43; 字符的匹配项。这个我i举个例子&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

txt <span class="token operator">&#61;</span> <span class="token string">&#34;5&#43;6&#61;11&#34;</span>

<span class="token comment">#检查字符串是否有任何 &#43; 字符&#xff1a;</span>

x <span class="token operator">&#61;</span> re.findall<span class="token punctuation">(</span><span class="token string">&#34;[&#43;]&#34;</span>, txt<span class="token punctuation">)</span>

print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>

<span class="token keyword">if</span> x:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配到了&#34;</span><span class="token punctuation">)</span>
else:
  print<span class="token punctuation">(</span><span class="token string">&#34;匹配不到&#34;</span><span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/350713dcf2674e969be75a4bcea51fbb.png" alt="在这里插入图片描述" /></p> 
<h2><a id="_5243"></a>六.匹配对象</h2> 
<p>匹配对象是包含有关搜索和结果的信息的对象。注意&#xff1a;如果没有匹配&#xff0c;None将返回值&#xff0c;而不是匹配对象。<br /> 直接举个例子&#xff1a;<br /> 执行将返回匹配对象的搜索</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

<span class="token comment">#search() 函数返回一个 Match 对象&#xff1a;</span>

txt <span class="token operator">&#61;</span> <span class="token string">&#34;hello world&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span><span class="token string">&#34;wo&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x<span class="token punctuation">)</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/a5b1967d4960485cb7b8d15f9d616204.png" alt="在这里插入图片描述" /></p> 
<p>Match 对象具有用于检索有关搜索和结果的信息的属性和方法&#xff1a;</p> 
<pre><code class="prism language-bash">span<span class="token punctuation">(</span><span class="token punctuation">)</span>返回一个包含匹配开始和结束位置的元组。
string返回传递给函数的字符串
group<span class="token punctuation">(</span><span class="token punctuation">)</span>返回字符串中匹配的部分
</code></pre> 
<h3><a id="61_span_5269"></a>6.1 span函数</h3> 
<p>例如&#xff1a;打印第一个匹配项的位置&#xff08;开始和结束位置&#xff09;。正则表达式查找任何以大写“S”开头的单词&#xff1a;</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

<span class="token comment">#搜索单词开头的大写“S”字符&#xff0c;并打印其位置</span>

txt <span class="token operator">&#61;</span> <span class="token string">&#34;The rain in Spain&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span>r<span class="token string">&#34;<span class="token entity" title="\b">\b</span>S\w&#43;&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x.span<span class="token punctuation">(</span><span class="token punctuation">))</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/3ef20a183fc54922be1bdde67ac15cca.png" alt="在这里插入图片描述" /></p> 
<h3><a id="62_string_5283"></a>6.2 string函数</h3> 
<p>例如&#xff1a;打印传递给函数的字符串</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

<span class="token comment">#返回字符串</span>

txt <span class="token operator">&#61;</span> <span class="token string">&#34;The rain in Spain&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span>r<span class="token string">&#34;<span class="token entity" title="\b">\b</span>S\w&#43;&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x.string<span class="token punctuation">)</span>
</code></pre> 
<h3><a id="63_group_5295"></a>6.3 group函数</h3> 
<p>例如&#xff1a;打印字符串中匹配的部分。正则表达式查找任何以大写“S”开头的单词</p> 
<pre><code class="prism language-bash"><span class="token function">import</span> re

<span class="token comment">#搜索单词开头的大写“w”字符&#xff0c;并打印该单词&#xff1a;</span>

txt <span class="token operator">&#61;</span> <span class="token string">&#34;hello world&#34;</span>
x <span class="token operator">&#61;</span> re.search<span class="token punctuation">(</span>r<span class="token string">&#34;<span class="token entity" title="\b">\b</span>w\w&#43;&#34;</span>, txt<span class="token punctuation">)</span>
print<span class="token punctuation">(</span>x.group<span class="token punctuation">(</span><span class="token punctuation">))</span>
</code></pre> 
<p>运行&#xff1a;<br /> <img src="https://img-blog.csdnimg.cn/b631a0be68464585ba4aeb1aee3c852d.png" alt="在这里插入图片描述" /><br /> <strong>注意</strong>&#xff1a;如果没有匹配&#xff0c;None将返回值&#xff0c;而不是匹配对象。</p> 
<h1><a id="_5310"></a>三十七、参考资料</h1> 
<p>《python从入门到实战》&#xff0c;需要电子版书记可以主页加我。</p> 
<p>菜鸟教程&#xff0c;确实很全&#xff1a;<br /> <code>https://www.runoob.com/python3/python3-tutorial.html</code></p> 
<p>python官方文文档&#xff1a;</p> 
<pre><code class="prism language-bash">https://docs.python.org/3/
</code></pre> 
<p>感谢这些资料&#xff0c;我才能写出这么全。</p> 
<h1><a id="_5322"></a>三十八、总结</h1> 
<p>本篇文章在前面写过的文章之上有过修改&#xff0c;并加入了正则表达式详细讲解&#xff0c;为什么我要出这么完整的文章而不是一篇一篇出呢&#xff1f;考虑到小白会看系列文章容易看糊涂&#xff0c;因此我在这里总结为一篇&#xff0c;保证任何人都可以从零到基础扎实。至此&#xff0c;python基础教程全部这一篇全部讲完了&#xff0c;希望大家支持三联一下。<br /> <img src="https://img-blog.csdnimg.cn/e4bead5a4af14064976162097952699e.png" alt="在这里插入图片描述" /></p> 
<p>创作实在不容易&#xff0c;希望能帮助到你学习&#xff0c;给我三联一下吧&#xff0c;我是<strong>川川菜鸟</strong>&#xff0c;有任何疑问都可以主页左侧加我的小窝。<br /> <img src="https://img-blog.csdnimg.cn/905eb7e0aeb54d788d5645e6d049c4ea.png" alt="在这里插入图片描述" /></p>
                </div>
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-d7a94ec6ab.css" rel="stylesheet">
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-49037e4d27.css" rel="stylesheet">
        </div>
        <div id="blogVoteBox" style="width:400px;margin:auto;margin-top:12px" class="blog-vote-box"></div>
        <div id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"></div>
    </article>
</div>
<div class="more-toolbox-new" id="toolBarBox">
    <div class="left-toolbox">
        <div class="toolbox-left">
            <div class="profile-box"><a class="profile-href" target="_blank" href="https://chuanchuan.blog.csdn.net"><img class="profile-img" src="https://profile.csdnimg.cn/9/1/6/3_weixin_46211269"><span class="profile-name">川川菜鸟</span></a></div>
            <div class="profile-attend">
                    <a class="tool-attend tool-bt-button tool-bt-attend" href="javascript:;" data-report-view='{"mod":"1592215036_002","spm":"1001.2101.3001.4232","extend1":"关注"}'>关注</a>
                <a class="tool-item-follow active-animation" style="display:none;">关注</a>
            </div>
        </div>
        <div class="toolbox-middle">
        <ul class="toolbox-list">
            <li class="tool-item tool-item-size tool-active is-like" id="is-like">
            <a class="tool-item-href">
                <img style="display:none;" id="is-like-imgactive-animation-like" class="animation-dom active-animation" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarThumbUpactive.png" alt="">
                <img class="isactive" style="display:none" id="is-like-imgactive" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart1Active.png" alt="">
                <img class="isdefault" style="display:block" id="is-like-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHeart1Black.png" alt="">  
                <span id="spanCount" class="count ">
                        1426
                </span>
            </a>
            <div class="tool-hover-tip"><span class="text space">点赞</span></div>
            </li>
            <li class="tool-item tool-item-size tool-active tool-item-comment">
            <a class="tool-item-href" href="#commentBox">
                <img class="isdefault" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCommentBlack.png" alt="">
                <span class="count">
                    208
                </span>
            </a>
            <div class="tool-hover-tip"><span class="text space">评论</span></div>
            </li>
            <li class="tool-item tool-item-size tool-active is-collection ">
            <a class="tool-item-href" href="javascript:;" data-report-click='{"mod":"popu_824","spm":"1001.2101.3001.4130","ab":"new"}'>
                <img style="display:none" id="is-collection-img-collection" class="animation-dom active-animation" src="https://csdnimg.cn/release/blogv2/dist/pc/img/tobarCollectionActive.png" alt="">
                <img class="isdefault" id="is-collection-img" style="display:block" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCollectBlack.png" alt="">
                <img class="isactive" id="is-collection-imgactive" style="display:none" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCollectActive.png" alt="">
                <span class="count get-collection " id="get-collection">
                    5690
                </span>
            </a>
            <div class="tool-hover-tip"><span class="text space">收藏</span></div>
            </li>
            <li class="tool-item tool-active">
                <a class="" href="javascript:;">
                    <img class="company active" id="health-companies" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newHealthCompanies1Active.gif" alt="一键三连">
                </a>
                <div class="tool-hover-tip three-click"><span class="text">一键三连</span></div>
            </li>
            <li class="tool-item tool-item-bar">
            </li>
            <li class="tool-item tool-item-size tool-active tool-QRcode" id="tool-share">
                <a class="tool-item-href" href="javascript:;" data-report-click='{"mod":"1582594662_002","spm":"1001.2101.3001.4129","ab":"new"}'>
                    <img class="isdefault" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newShareBlack.png" alt="">
                </a>
                <div class="QRcode" id="tool-QRcode">
                    <p class="title">
                    扫一扫，分享海报
                    </p>
                    <div id='shareCode'></div>
                </div>
            </li>
        </ul>
        </div>
        <div class="toolbox-right">
                <div class="tool-directory">
                    <a class="bt-columnlist-show"
                    data-id="11313211"
                    data-free="true"
                    data-subscribe="false"
                    data-title="python全栈基础教程系列"
                    data-img="https://img-blog.csdnimg.cn/20210825184045537.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224"
                    data-url="https://blog.csdn.net/weixin_46211269/category_11313211.html"
                    data-sum="28"
                    data-people="341"
                    data-price="0"
                    data-oldprice="0"
                    data-join="false"
                    data-studyvip="false"
                    data-studysubscribe="false"
                    data-report-view='{"spm":"1001.2101.3001.6334","extend1":"专栏目录"}'
                    data-report-click='{"spm":"1001.2101.3001.6334","extend1":"专栏目录"}'
                    >专栏目录</a>
                </div>
        </div>
    </div>  
</div>
<script type=text/javascript crossorigin src="https://csdnimg.cn/release/phoenix/production/qrcode-7c90a92189.min.js"></script>
<script src="//g.csdnimg.cn/??sharewx/1.2.1/sharewx.js" type="text/javascript"></script>
<script type="text/javascript" crossorigin src="https://g.csdnimg.cn/user-login/3.0.1/user-login.js"></script>
<script type="text/javascript" crossorigin src="https://g.csdnimg.cn/collection-box/2.0.6/collection-box.js"></script>
                <div class="first-recommend-box recommend-box">
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/m0_60721065/article/details/120323748"  data-report-view='{"ab":"new","mod":"popu_871","extra":"{\"utm_medium\":\"distribute.pc_relevant_t0.587850\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","index":"1","style":"text_1","strategy":"32_587850_RCMD","dest":"https://blog.csdn.net/m0_60721065/article/details/120323748"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/m0_60721065/article/details/120323748" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_871","extra":"{\"utm_medium\":\"distribute.pc_relevant_t0.587850\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","index":"1","style":"text_1","strategy":"32_587850_RCMD","dest":"https://blog.csdn.net/m0_60721065/article/details/120323748"}'  data-report-query='utm_medium=distribute.pc_relevant_t0.587850&depth_1-utm_source=distribute.pc_relevant_t0.587850'>
					<div class="left ellipsis-online ellipsis-online-1">深度学习：TensorFlow入门实战</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/m0_60721065" target="_blank"><span class="blog-title">m0_60721065的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-16</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					180
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/m0_60721065/article/details/120323748" target="_blank"  data-report-click='{"ab":"new","mod":"popu_871","extra":"{\"utm_medium\":\"distribute.pc_relevant_t0.587850\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","index":"1","style":"text_1","strategy":"32_587850_RCMD","dest":"https://blog.csdn.net/m0_60721065/article/details/120323748"}'  data-report-query='utm_medium=distribute.pc_relevant_t0.587850&depth_1-utm_source=distribute.pc_relevant_t0.587850'>
				<div class="desc ellipsis-online ellipsis-online-1">推荐下我自己建的人工智能<em>Python</em>学习群:[809160367]，群里都是学<em>Python</em>的，如果你想学或者正在学习<em>Python</em> ，欢迎你加入，大家都是软件开发党，不定期分享干货，还有免费直播课程领取。包括我自己整理的一份2021最新的<em>Python</em>进阶资料和零基础教学，欢迎进阶中和对<em>Python</em>感兴趣的小伙伴加入！还可以扫码加VX领取资料哦！下面是正文本章介绍一个现阶段使用最广泛的深层学习框架&mdash;&mdash;TensorFlow。因为TensorFlow所拥有的社区支持度日益增长，所以使用它来构建...</div>
			</a>
		</div>
	</div>
</div>
                </div>
            <div class="second-recommend-box recommend-box">
<div class="recommend-item-box type_download clearfix" data-url="http://download.csdn.net/download/weixin_46211269/21918971"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-download-2~default~CTRLIST~default-1.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"1","strategy":"2~default~CTRLIST~default","dest":"http://download.csdn.net/download/weixin_46211269/21918971"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="http://download.csdn.net/download/weixin_46211269/21918971" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-download-2~default~CTRLIST~default-1.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"1","strategy":"2~default~CTRLIST~default","dest":"http://download.csdn.net/download/weixin_46211269/21918971"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>爆肝</em><em>十二万</em><em>字</em>《<em>python</em>从<em>零到</em><em>精通</em><em>教程</em>》，从<em>零教</em>你<em>变</em><em>大佬</em>（<em>建议</em><em>收藏</em>）.md</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info display-flex">
					<span class="info-block">09-04</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="http://download.csdn.net/download/weixin_46211269/21918971" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-download-2~default~CTRLIST~default-1.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"1","strategy":"2~default~CTRLIST~default","dest":"http://download.csdn.net/download/weixin_46211269/21918971"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-download-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-download-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">博客也有，如果需要本地文件，可下载。未经允许不得转载传阅。</div>
			</a>
		</div>
	</div>
</div>
            </div>
<a id="commentBox" name="commentBox"></a>
<div class="comment-box">
	<div class="comment-edit-box d-flex">
		<a id="commentsedit"></a>
		<div class="user-img">
			<a href="javascript:void(0);" >
				<img class="show_loginbox" src="https://g.csdnimg.cn/static/user-img/anonymous-User-img.png">
			</a>
		</div>
		<form id="commentform">
			<img class="comment-sofa-flag" src="https://csdnimg.cn/release/blogv2/dist/pc/img/commentFlag@2x.png">
      <textarea class="comment-content" name="comment_content" id="comment_content" placeholder="优质评论可以帮助作者获得更高权重" maxlength="1000"></textarea>
			<div class="comment-emoticon"><img class="comment-emoticon-img" data-url="https://csdnimg.cn/release/blogv2/dist/pc/img/" src="https://csdnimg.cn/release/blogv2/dist/pc/img/emoticon.png" alt="表情包"></div> 
      <span class="comment-emoticon-tip">插入表情</span>
      <div class="comment-emoticon-box">
        <div class="comment-emoticon-img-box"></div>
			</div>
      <div class="opt-box">
				<div id="ubbtools" class="add_code">
					<a href="#insertcode" code="code" target="_self"><i class="icon iconfont icon-daima"></i></a>
				</div>
				<input type="hidden" id="comment_replyId" name="comment_replyId">
				<input type="hidden" id="article_id" name="article_id" value="120076709">
				<input type="hidden" id="comment_userId" name="comment_userId" value="">
				<input type="hidden" id="commentId" name="commentId" value="">
				<div class="dropdown" id="myDrap">
					<a class="dropdown-face d-flex align-items-center" data-toggle="dropdown" role="button"
						aria-haspopup="true" aria-expanded="false">
						<div class="txt-selected text-truncate">添加代码片</div>
						<svg class="icon d-block" width="200px" height="100.00px" viewBox="0 0 2048 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path  d="M597.33333292 298.666667h853.333334L1023.99999992 725.333333 597.33333292 298.666667z"  /></svg>
					</a>
					<ul class="dropdown-menu" id="commentCode" aria-labelledby="drop4">
						<li><a data-code="html">HTML/XML</a></li>
						<li><a data-code="objc">objective-c</a></li>
						<li><a data-code="ruby">Ruby</a></li>
						<li><a data-code="php">PHP</a></li>
						<li><a data-code="csharp">C</a></li>
						<li><a data-code="cpp">C++</a></li>
						<li><a data-code="javascript">JavaScript</a></li>
						<li><a data-code="python">Python</a></li>
						<li><a data-code="java">Java</a></li>
						<li><a data-code="css">CSS</a></li>
						<li><a data-code="sql">SQL</a></li>
						<li><a data-code="plain">其它</a></li>
					</ul>
				</div>
				<div class="right-box" id="rightBox" data-type="2">
							<span id="tip_comment" class="tip">还能输入<em>1000</em>个字符</span>
							<a data-report-click='{"mod":"1582594662_003","spm":"1001.2101.3001.4227","ab":"new"}'><input type="submit"
									class="btn btn-sm btn-comment" value="发表评论"></a>
				</div>
			</div>
		</form>
		<input type="button" class="bt-comment-show" value="评论">
	</div>
	<div class="comment-list-container">
		<a id="comments"></a>
		<div class="comment-list-box">
		</div>
		<div id="commentPage" class="pagination-box d-none"></div>
		<div class="opt-box text-center">
			<div class="btn btn-sm btn-link-blue" id="btnMoreComment"></div>
		</div>
	</div>
</div>            <div class="recommend-box insert-baidu-box">
                <div class="recommend-item-box clearfix" style="display:none"></div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-2.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"2","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-2.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"2","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>三万<em>字</em>《十大算法入门》<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/WhereIsHeroFrom" target="_blank"><span class="blog-title">英雄哪里出来</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">07-27</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					7861
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-2.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"2","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119112449"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">3万<em>字</em>详细解读《十大入门算法》</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/windowsxp2018/article/details/107970662"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-3.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"3","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/windowsxp2018/article/details/107970662"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/windowsxp2018/article/details/107970662" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-3.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"3","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/windowsxp2018/article/details/107970662"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1">什么样的程序员才算真正的大神？</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/windowsxp2018" target="_blank"><span class="blog-title">极客小俊</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">08-13</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					1207
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/windowsxp2018/article/details/107970662" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-3.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"3","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/windowsxp2018/article/details/107970662"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">完全<em>精通</em>计算机底层原理才能是真正的<em>大佬</em>  这本质是没有错，但是我也不敢苟同，程序这玩意儿，一辈子都学不完。能<em>精通</em>一种的，都是<em>大佬</em>、
不是会多少开发语言，多少算法，多少框架 而是解决问题的思路，方法和技巧  但往往始终喜欢谈论框架语言的又感觉low了 所以把握好这个中间度是必然的 、
技术服务业务，不然写再多代码也创造不了价值 而并非有些人所说，在一个底层死磕  [嘻哈猴抽烟酷][嘻哈猴抽烟酷][嘻哈猴抽烟酷][嘻哈猴哭哭][嘻哈猴哭哭][嘻哈猴哭哭]

...</div>
			</a>
		</div>
	</div>
</div>
		<dl id="recommend-item-box-tow" class="recommend-item-box type_blog clearfix">
			
		</dl>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_31504783/article/details/118324021"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-4.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"4","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_31504783/article/details/118324021"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_31504783/article/details/118324021" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-4.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"4","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_31504783/article/details/118324021"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1">计算机基础知识试题选择题,计算机基础知识试题及答案选择题</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_31504783" target="_blank"><span class="blog-title">weixin_31504783的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">06-28</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					41
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_31504783/article/details/118324021" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-4.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"4","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_31504783/article/details/118324021"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">计算机基础知识试题及答案选择题(一)基础一、  选择题1、  世界上首先实现存储程序的电子数<em>字</em>计算机是____。   A、ENIAC  B、UNIVAC  C、EDVAC  D、EDSAC   2、计算机科学的奠基人是____。   A、查尔斯.巴贝奇        B、图灵   C、阿塔诺索夫      D、冯.诺依曼2、  世界上首次提出存储程序计算机体系结构的是____。A、艾仑?图灵   ...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/qq_36903042/article/details/102792114"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-5.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"5","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/qq_36903042/article/details/102792114"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/qq_36903042/article/details/102792114" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-5.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"5","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/qq_36903042/article/details/102792114"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-5.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-5.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1">大学四年，我把私藏的自学「学习网站/实用工具」都贡献出来了</div>
					<div class="tag">热门推荐</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/qq_36903042" target="_blank"><span class="blog-title">小鹿动画学编程</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">10-29</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					18万+
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/qq_36903042/article/details/102792114" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-5.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"5","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/qq_36903042/article/details/102792114"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-5.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-5.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">在分享之前，先说说初学者如何学习编程，这个话题想必非常的重要，要学好编程，给你一些学习网站也好、实用工具也好，但前提是你知道如何去学习它。
见过很多初学者，以及小鹿我刚开始学习的时候，也是自己瞎摸索，找不到路子，看什么书？看什么资料？编程的方向太多了，如果确定自己的方向？尤其是上大一、大二甚至大三还没有确定自己到底是学习前端还是后天，每天这学一点，那学一块，掌握那么多，没有一门<em>精通</em>的，去面试的时候...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120119821"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-6.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"6","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119821"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120119821" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-6.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"6","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119821"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-6.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（六）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					72
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120119821" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-6.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"6","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119821"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-6.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">FTP是因特网上最早使用的文件传输程序，使用FTP不能____。


A、查看文件 B、文件目录操作

C、下载文件 D、运行文件


WWW是一种建立在Internet上的全球性的、交互的、动态、多平台、分布式的图形信息系统，它的最基本的概念是____。


A、HypertextB、Text C、File D、Multimedia


...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120119337"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-7.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"7","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119337"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120119337" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-7.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"7","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119337"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-7.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-7.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（四）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					80
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120119337" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-7.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"7","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119337"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-7.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-7.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">151. www.cernet.edu.cn 的网址中，可以明确地看出是属于哪一类机构____。


A、教育界B、政府单位 C、法人组织 D、公司


152. 在Wed网页中指向其他网页的&lsquo;指针&ldquo;称之为____。


A、超链接B、超文本 C、超媒体 D、多媒体


153. 下列关于URL的解释错误的是____。


A、它是一种网络服务B、它的中文意思是统一资源定位器 

C、它是WWW页的地址 D、它由4部分组成


154. 因特网上专门提供网上搜索的工具叫__...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120120246"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-8.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"8","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120120246"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120120246" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-8.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"8","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120120246"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-8.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（九）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
					<div class="tag">最新发布</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					112
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120120246" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-8.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"8","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120120246"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-8.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">在PowerPoint2000中，若为幻灯片中的对象设置&quot;飞入&quot;，应选择对话框____。


A、自定义动画B、幻灯片版式 C、自定义放映 D、幻灯处放映


在编辑Word文档时，输入的新<em>字</em>符总是覆盖了文档中已经输入的<em>字</em>符，_____。


A、原因是当前文档正处在改写的编辑方式

B、原因是当前文档正处在插入的编辑方式

C、连按两次Insert键，可防覆盖发生

D、按Delete键可防止覆盖发生


要在Word文档中插入数学公式，可利用_____命令。


A、&ldquo;工具｜选项&rdquo; ...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120119989"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-9.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"9","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119989"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120119989" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-9.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"9","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119989"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-9.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（七）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					68
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120119989" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-9.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"9","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119989"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-9.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">在Word中，对某个段落的全部文<em>字</em>进行下列设置，属于段落格式设置的是____。


A、设置为四号<em>字</em> B、设置为楷体<em>字</em>

C、设置为1.5倍行距D、设置为4磅<em>字</em>间距


用Word编辑文件时，用户可以设置文件的自动保存时间间隔。如果改<em>变</em>自动保存时间间隔，将选择____。


A、视图菜单 B、编辑菜单 C、格式菜单 D、工具菜单


在Word中，文档中每一页都要出现的基本相同的内容都应放在____中。


A、页眉页脚B、文本 ...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120119520"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-10.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"10","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119520"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120119520" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-10.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"10","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119520"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-10.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（五）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					80
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120119520" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-10.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"10","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120119520"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-10.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">客户/服务器模式的局域网，其网络硬件主要包括服务器、工作站、网卡和____。


A、网络拓扑结构 B、计算机C、传输介质D、网络协议


和广域网相比，局域网____。


A、有效性好但可靠性差 B、有效性差但可靠性高

C、有效性好可靠性也高D、有效性差可靠性也差


计算机网络技术包含的两个主要技术是计算机技术和____。


A、微电子技术 B、通信技术C、数据处理技术 D、自动化技术


OSI（开放系统互联)参考...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-11.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"11","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-11.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"11","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>三万<em>字</em>《C语言动漫<em>教程</em>》<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/WhereIsHeroFrom" target="_blank"><span class="blog-title">英雄哪里出来</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">06-24</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					5628
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-11.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"11","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/118163916"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">已经更新最新版本</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://xiaoxuzhu.blog.csdn.net/article/details/119959683"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-12.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"12","strategy":"2~default~CTRLIST~default","dest":"https://xiaoxuzhu.blog.csdn.net/article/details/119959683"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://xiaoxuzhu.blog.csdn.net/article/details/119959683" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-12.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"12","strategy":"2~default~CTRLIST~default","dest":"https://xiaoxuzhu.blog.csdn.net/article/details/119959683"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-12.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-12.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>Jenkins从<em>零到</em>壹<em>❤</em><em>️</em> 两万<em>字</em>Jenkins<em>教程</em>大全汇总（JAVA 小虚竹 <em>建议</em><em>收藏</em>）</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/shi_hong_fei_hei" target="_blank"><span class="blog-title">小虚竹的专栏</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					5673
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://xiaoxuzhu.blog.csdn.net/article/details/119959683" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-12.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"12","strategy":"2~default~CTRLIST~default","dest":"https://xiaoxuzhu.blog.csdn.net/article/details/119959683"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-12.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-12.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>Jenkins从<em>零到</em>壹<em>❤</em><em>️</em> 两万<em>字</em>Jenkins<em>教程</em>大全汇总（JAVA java  小虚竹）</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-13.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"13","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-13.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"13","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-13.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>五万<em>字</em>《十大排序算法》动图讲解<em>❤</em><em>️</em>(<em>建议</em><em>收藏</em>)</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/WhereIsHeroFrom" target="_blank"><span class="blog-title">英雄哪里出来</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">08-29</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					4万+
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-13.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"13","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/WhereIsHeroFrom/article/details/119976287"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-13.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">打开算法大门，从排序开始</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_53173799/article/details/119541605"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-14.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"14","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_53173799/article/details/119541605"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_53173799/article/details/119541605" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-14.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"14","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_53173799/article/details/119541605"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-14.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1">你觉得学 <em>Python</em> 还是 Java 更好找工作？</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_53173799" target="_blank"><span class="blog-title">weixin_53173799的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">08-09</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					1388
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_53173799/article/details/119541605" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-14.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"14","strategy":"2~default~CTRLIST~default","dest":"https://blog.csdn.net/weixin_53173799/article/details/119541605"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-14.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">【此文章转自乐<em>字</em>节】
对于程序员初学者，或者稍微了解互联网行业的人，这几年最频繁地听到的两种编程语言就是 <em>Python</em> 与 Java 。
如果你问一名 Java 程序员，肯定会<em>建议</em>你先学 Java，因为他们认为<em>Python</em>像个乳臭未干的黄毛小子；但如果你问 <em>Python</em> 程序员，可能会得到一个完全相反的答案，他们认为 Java 是刻板啰嗦的老大爷，而人生苦短，我用 <em>Python</em> 。
所以，如果你是纠结于选 <em>Python</em> 还是 Java，说实话，我很难给一个明确的答案，但如果问的是，对于一般人是学 Pyth.</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://tefuirnever.blog.csdn.net/article/details/104545515"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-15.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"15","strategy":"2~default~CTRLIST~default","dest":"https://tefuirnever.blog.csdn.net/article/details/104545515"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://tefuirnever.blog.csdn.net/article/details/104545515" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-15.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"15","strategy":"2~default~CTRLIST~default","dest":"https://tefuirnever.blog.csdn.net/article/details/104545515"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-15.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1">【程序员日记】快乐的一周嘛（第6期）（财富、快乐、技术）</div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/TeFuirnever" target="_blank"><span class="blog-title">种树最好的时间是10年前，其次是现在！！！</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">02-27</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					1863
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://tefuirnever.blog.csdn.net/article/details/104545515" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-15.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"15","strategy":"2~default~CTRLIST~default","dest":"https://tefuirnever.blog.csdn.net/article/details/104545515"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-15.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">欢迎关注WX公众号：【程序员管小亮】
文章目录欢迎关注WX公众号：【程序员管小亮】声明1、财富2、快乐1）妈妈，我真的在B站学习2）KFC&ldquo;炸鸡鞋&rdquo;3、技术1）C++坦克大战2）wordart3）VS Code实时可视化Debug4）C++总结往期内容回顾
声明
以下文章全部发在本人微信公众号中，图片来自网络，无广告收入，如果你觉得快乐，可以去公众号赞赏一杯咖啡/饮料。

人都是花了好长时间才能搞...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120117735"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-16.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"16","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120117735"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120117735" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-16.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"16","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120117735"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-16.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（三）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-05</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					65
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120117735" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-16.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"16","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120117735"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-16.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">推荐阅读：

<em>❤</em><em>️</em>《计算机基础知识》（一）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em>

<em>❤</em><em>️</em>《计算机基础知识》（二）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em>

<em>❤</em><em>️</em> java项目精品实战案例 <em>❤</em><em>️</em>



101. Internet上，访问Web信息时用的工具是浏览器。下列____就是目前常用的Web浏览器之一。


A、Internet ExplorerB、Outlook Express  C、Yahoo D、FrontPage


102. 互联网上的服务都基于一种协议，...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120048801"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-17.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"17","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120048801"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120048801" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-17.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"17","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120048801"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-17.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（二）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-01</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					1342
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120048801" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-17.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"17","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120048801"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-17.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">上一篇：

<em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（一）<em>❤</em><em>️</em>



51、 Access是一种____数据库管理系统。


A、发散型 B、集中型 C、关系型 D、逻辑型


52、 用高级程序设计语言编写的程序，要转换成等价的可执行程序，必须经过____。


A、汇编 B、编辑 C、解释 D、编译和连接


53、 一般用高级语言编写的应用程序称为____。


A、编译程序 B、编辑程序 C、连接程序 D、源程序


54、 若微机系统需要热启动，应同时按下组合键____。


A、Ct...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://lyyong.blog.csdn.net/article/details/120026752"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-18.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"18","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120026752"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://lyyong.blog.csdn.net/article/details/120026752" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-18.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"18","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120026752"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-18.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-18.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>六W<em>字</em>《计算机基础知识》（一）（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_39709134" target="_blank"><span class="blog-title">java李阳勇的博客</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">08-31</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					1276
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://lyyong.blog.csdn.net/article/details/120026752" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-18.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"18","strategy":"2~default~essearch~vector","dest":"https://lyyong.blog.csdn.net/article/details/120026752"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-18.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-18.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">计算机简介：


   计算机（computer）俗称电脑，是现代一种用于高速计算的电子计算机器，可以进行数值计算，又可以进行逻辑计算，还具有存储记忆功能。是能够按照程序运行，自动、高速处理海量数据的现代化智能电子设备。由硬件系统和软件系统所组成，没有安装任何软件的计算机称为裸机。可分为超级计算机、工业控制计算机、网络计算机、个人计算机、嵌入式计算机五类，较先进的计算机有生物计算机、光子计算机、量子计算机等。

      计算机发明者约翰&middot;冯&middot;诺依曼。计算机是20世纪最先进的科学技...</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_50569789/article/details/116355078"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-19.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"19","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/116355078"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_50569789/article/details/116355078" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-19.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"19","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/116355078"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-19.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-19.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>《网络编程从入门到入魔》（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_50569789" target="_blank"><span class="blog-title">Welcome to 七元K home page</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">05-02</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					315
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_50569789/article/details/116355078" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-19.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"19","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/116355078"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-19.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-19.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">网络编程
1.1、 概述

计算机网络
		是指将地理位置不同的具有独立功能的多台计算机及其外部设备，
		通过通信线路连接起来，
		在网络操作系统，网络管理软件及网络通信协议的管理和协调下，
		实现资源共享和信息传递的计算机系统。

网络编程
		就是用来实现网络互连的不同计算机上运行的程序间可以进行数据交换。

1.2、网络通讯的要素

规则：网络通信协议




OSI中的层
功能
TCP/IP协议族




应用层
文件传输，电子邮件，文件服务，虚拟终端
TFTP，HTTP，SNMP，FTP，S</div>
			</a>
		</div>
	</div>
</div>
<div class="recommend-item-box type_blog clearfix" data-url="https://blog.csdn.net/weixin_50569789/article/details/120031414"  data-report-view='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-20.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"20","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/120031414"}'>
	<div class="content-box">
		<div class="content-blog display-flex">
			<div class="title-box">
				<a href="https://blog.csdn.net/weixin_50569789/article/details/120031414" class="tit" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-20.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"20","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/120031414"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-20.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-20.no_search_link'>
					<div class="left ellipsis-online ellipsis-online-1"><em>❤</em><em>️</em>《Mybatis从基础到高级》（<em>建议</em><em>收藏</em>）<em>❤</em><em>️</em></div>
				</a>
			</div>
			<div class="info-box display-flex">
				<div class="info">
					<a href="https://blog.csdn.net/weixin_50569789" target="_blank"><span class="blog-title">Welcome to 七元K home page</span></a>
				</div>
				<div class="info display-flex">
					<span class="info-block time">09-01</span>
					<span class="info-block read"><img class="read-img" src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					762
					</span>
				</div>
			</div>
		</div>
		<div class="desc-box">
			<a href="https://blog.csdn.net/weixin_50569789/article/details/120031414" target="_blank"  data-report-click='{"ab":"new","mod":"popu_387","extra":"{\"utm_medium\":\"distribute.pc_relevant.none-task-blog-2~default~essearch~vector-20.no_search_link\",\"dist_request_id\":\"1631862579768_05735\"}","dist_request_id":"1631862579768_05735","ab_strategy":"ctrlist","index":"20","strategy":"2~default~essearch~vector","dest":"https://blog.csdn.net/weixin_50569789/article/details/120031414"}'  data-report-query='utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-20.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7Eessearch%7Evector-20.no_search_link'>
				<div class="desc ellipsis-online ellipsis-online-1">Mybatis

1、简介

MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了[google code](https://baike.baidu.com/item/google code/2346604)，并且改名为MyBatis 。2013年11月迁移到Github。
iBATIS一词来源于&ldquo;internet&rdquo;和&ldquo;abatis&rdquo;的组合，是一个基于Java的持久层框架。
iBATIS提供的持久层框架包括SQL M</div>
			</a>
		</div>
	</div>
</div>
            </div>
            <div class="template-box">
                <span>©️2020 CSDN</span>
                <span>皮肤主题: 岁月</span>
                <span> 设计师:pinMode</span>
                <span>
                    <a href="https://blog.csdn.net/" class="back-home c-blue c-blue-hover c-blue-focus">返回首页</a>
                </span>
            </div>
<div class="blog-footer-bottom" style="margin-top:10px;"></div>
<script src="https://g.csdnimg.cn/common/csdn-footer/csdn-footer.js" data-isfootertrack="false" type="text/javascript"></script>
<script type="text/javascript">
    window.csdn.csdnFooter.options = {
        el: '.blog-footer-bottom',
        type: 2
    }
</script>        </main>
<aside class="blog_container_aside">
	<div id="asideProfile" class="aside-box">
    <div class="profile-intro d-flex">
        <div class="avatar-box d-flex justify-content-center flex-column">
            <a href="https://chuanchuan.blog.csdn.net" data-report-click='{"mod":"popu_379","spm":"1001.2101.3001.4121","dest":"https://chuanchuan.blog.csdn.net","ab":"new"}'>
                <img src="https://profile.csdnimg.cn/9/1/6/3_weixin_46211269" class="avatar_pic">
            </a>
        </div>
        <div class="user-info d-flex flex-column profile-intro-name-box">
            <div class="profile-intro-name-boxTop">
                <a href="https://chuanchuan.blog.csdn.net" class="" id="uid" title="川川菜鸟" data-report-click='{"mod":"popu_379","spm":"1001.2101.3001.4122","dest":"https://chuanchuan.blog.csdn.net","ab":"new"}'>
                    <span class="name vip-name" username="weixin_46211269">川川菜鸟</span>
                </a>
                <span>
                <img class="identity" src="https://csdnimg.cn/release/blogv2/dist/mobile/img/vipNew.png" alt="">
                </span>
                <span class="flag expert-blog">
                <span class="bubble">CSDN认证博客专家</span>
                </span>
                <span class="flag company-blog">
                <span class="bubble">CSDN认证企业博客</span>
                </span>
            </div>
            <div class="profile-intro-name-boxFooter">
                <span class="personal-home-page personal-home-years">码龄2年</span>
                    <span class="personal-home-page">
                    <a class="personal-home-certification" href="https://i.csdn.net/#/uc/profile?utm_source=14998968" target="_blank" title="算法领域新星创作者">
                    <img src="https://img-home.csdnimg.cn/images/20210412060958.png" alt="">
                    算法领域新星创作者
                    </a>
                    </span>
            </div>
        </div>
    </div>
    <div class="data-info d-flex item-tiling">
        <dl class="text-center" title="407">
            <a href="https://chuanchuan.blog.csdn.net" data-report-click='{"mod":"1598321000_001","spm":"1001.2101.3001.4310"}' data-report-query="t=1">  
                <dt><span class="count">407</span></dt>
                <dd class="font">原创</dd>
            </a>
        </dl>
        <dl class="text-center" data-report-click='{"mod":"1598321000_002","spm":"1001.2101.3001.4311"}' title="5">
            <a href="https://blog.csdn.net/rank/list/weekly" target="_blank">
                <dt><span class="count">5</span></dt>
                <dd class="font">周排名</dd>
            </a>
        </dl>
        <dl class="text-center" title="483">
            <a href="https://blog.csdn.net/rank/list/total" data-report-click='{"mod":"1598321000_003","spm":"1001.2101.3001.4312"}' target="_blank">
                <dt><span class="count">483</span></dt>
                <dd class="font">总排名</dd>
            </a>
        </dl>
        <dl class="text-center" style="min-width:58px" title="576542">  
            <dt><span class="count">57万+</span></dt>
            <dd>访问</dd>
        </dl>
        <dl class="text-center" title="7级,点击查看等级说明">
            <dt><a href="https://blog.csdn.net/blogdevteam/article/details/103478461" target="_blank">
                <img class="level" src="https://csdnimg.cn/identity/blog7.png">
            </a>
            </dt>
            <dd>等级</dd>
        </dl>
    </div>
    <div class="item-rank"></div>
    <div class="data-info d-flex item-tiling">
        <dl class="text-center" title="18844">
            <dt><span class="count">1万+</span></dt>
            <dd>积分</dd>
        </dl>
         <dl class="text-center" id="fanBox" title="12799">
            <dt><span class="count" id="fan">1万+</span></dt>
            <dd>粉丝</dd>
        </dl>
        <dl class="text-center" title="9208">
            <dt><span class="count">9208</span></dt>
            <dd>获赞</dd>
        </dl>
        <dl class="text-center" title="3954">
            <dt><span class="count">3954</span></dt>
            <dd>评论</dd>
        </dl>
        <dl class="text-center" title="23967">
            <dt><span class="count">2万+</span></dt>
            <dd>收藏</dd>
        </dl>
    </div>
    <div class="aside-box-footer" data-report-view='{"spm":"3001.4296"}'>
        <div class="badge-box d-flex">
            <div class="badge d-flex">
                <div class="icon-badge" title="GitHub">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/github@240.png" alt="GitHub">
                    </div>
                </div>
                <div class="icon-badge" title="签到新秀">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/qiandao20@240.png" alt="签到新秀">
                    </div>
                </div>
                <div class="icon-badge" title="阅读者勋章Lv3">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/yuedu30@240.png" alt="阅读者勋章Lv3">
                    </div>
                </div>
                <div class="icon-badge" title="持之以恒">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/chizhiyiheng@240.png" alt="持之以恒">
                    </div>
                </div>
                <div class="icon-badge" title="勤写标兵Lv4">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/qixiebiaobing4@240.png" alt="勤写标兵Lv4">
                    </div>
                </div>
                <div class="icon-badge" title="分享宗师">
                    <div class="mouse-box">
                        <img class="medal-img" data-report-click='{"spm":"3001.4296"}' src="https://csdnimg.cn/medal/fenxiangzongshi@240.png" alt="分享宗师">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="profile-intro-name-boxOpration">
        <div class="opt-letter-watch-box">
        <a class="bt-button personal-letter" href="https://im.csdn.net/chat/weixin_46211269" target="_blank" rel="noopener">私信</a>
        </div>
        <div class="opt-letter-watch-box"> 
            <a class="personal-watch bt-button" id="btnAttent" >关注</a>  
        </div>
    </div>
</div>
<div id="asideSearchArticle" class="aside-box">
	<div class="aside-content search-comter">
    <div class="aside-search aside-search-blog">         
        <input type="text" class="input-serch-blog" name="" autocomplete="off" value="" id="search-blog-words" placeholder="搜博主文章">
        <a class="btn-search-blog">
                    <img src="//csdnimg.cn/cdn/content-toolbar/csdn-white-search.png?v=1587006908">
        </a>
    </div>
    </div>
</div>

<div id="asideCustom" class="aside-box custom-box">
    <h3 class="aside-title">非营销私人粉丝群&#xff0c;非诚勿扰</h3>
    <div class="aside-content clearfix">
        博主自身刚步入大三的学生&#xff0c;尽量帮助到大家。欢迎加入大家庭一起学习&#xff0c;有问题随便问&#xff0c;本来就互相学习的交流群&#xff0c;非营销号。仅限粉丝进群。 python全栈交流群&#xff1a; 
<img src="https://img-blog.csdnimg.cn/409f9cd63e71400ebde717fc46e5945d.png" alt="29f491d075774ac3bcf7976e699c388d.png" /> c/c&#43;&#43;学习交流群&#xff1a; 
<img src="https://img-blog.csdnimg.cn/ac1019de456745799c04673e045a3e86.png" alt="ac1019de456745799c04673e045a3e86.png" />
    </div>
</div>

<div id="asideHotArticle" class="aside-box">
	<h3 class="aside-title">热门文章</h3>
	<div class="aside-content">
		<ul class="hotArticle-list">
			<li>
				<a href="https://chuanchuan.blog.csdn.net/article/details/120076709" target="_blank"  data-report-click='{"mod":"popu_541","spm":"1001.2101.3001.4139","dest":"https://chuanchuan.blog.csdn.net/article/details/120076709","ab":"new"}'>
				❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）
					<img src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					<span class="read">56461</span>
                </a>
			</li>
			<li>
				<a href="https://chuanchuan.blog.csdn.net/article/details/119814777" target="_blank"  data-report-click='{"mod":"popu_541","spm":"1001.2101.3001.4139","dest":"https://chuanchuan.blog.csdn.net/article/details/119814777","ab":"new"}'>
				肝通宵写了三万字把SQL数据库的所有命令，函数，运算符讲得明明白白讲解，内容实在丰富，建议收藏+三连好评！
					<img src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					<span class="read">51036</span>
                </a>
			</li>
			<li>
				<a href="https://chuanchuan.blog.csdn.net/article/details/117921934" target="_blank"  data-report-click='{"mod":"popu_541","spm":"1001.2101.3001.4139","dest":"https://chuanchuan.blog.csdn.net/article/details/117921934","ab":"new"}'>
				手把手教你python制作一个完整qq机器人
					<img src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					<span class="read">33929</span>
                </a>
			</li>
			<li>
				<a href="https://chuanchuan.blog.csdn.net/article/details/119852902" target="_blank"  data-report-click='{"mod":"popu_541","spm":"1001.2101.3001.4139","dest":"https://chuanchuan.blog.csdn.net/article/details/119852902","ab":"new"}'>
				【肝帝一周总结：全网最全最细】十万字python教程，学不会找我！教到你会为止！！内容超多，建议收藏慢慢看！
					<img src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					<span class="read">31582</span>
                </a>
			</li>
			<li>
				<a href="https://chuanchuan.blog.csdn.net/article/details/119963298" target="_blank"  data-report-click='{"mod":"popu_541","spm":"1001.2101.3001.4139","dest":"https://chuanchuan.blog.csdn.net/article/details/119963298","ab":"new"}'>
				不会用github？全中文CSDN代码托管平台值得你拥有！手把手教你学会使用！！
					<img src="https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png" alt="">
					<span class="read">28611</span>
                </a>
			</li>
		</ul>
	</div>
</div>
<div id="asideCategory" class="aside-box flexible-box">
    <h3 class="aside-title">分类专栏</h3>
    <div class="aside-content">
        <ul>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11242184.html" data-report-click='{"mod":"popu_826","spm":"1001.2101.3001.4230","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11242184.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20210909221847641.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">数学建模小白到精通系列</span>
                        <img class="tip" src="https://csdnimg.cn/release/blogv2/dist/pc/img/payMoney.png" alt="">
                    </span>
                    <span class="count float-right">51篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11313211.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11313211.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20210825184045537.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">python全栈基础教程系列</span>
                    </span>
                    <span class="count float-right">28篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11324293.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11324293.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">matlab语音信号处理</span>
                    </span>
                    <span class="count float-right">4篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11320323.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11320323.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">零基础进军人工智能教程</span>
                    </span>
                    <span class="count float-right">10篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11329089.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11329089.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20190918135101160.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">C++从零到精通教程系列</span>
                    </span>
                    <span class="count float-right">3篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11310522.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11310522.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20190927151117521.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">c语言数据结构教程系列</span>
                    </span>
                    <span class="count float-right">2篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10912318.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10912318.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20210825184642604.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">qq机器人小白教程系列</span>
                    </span>
                    <span class="count float-right">27篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10532683.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10532683.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/20190927151043371.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">python案例和工具</span>
                    </span>
                    <span class="count float-right">64篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10425986.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10425986.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/2021082518423471.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">瞎写点爬虫教程案例</span>
                    </span>
                    <span class="count float-right">23篇</span>
                </a>
            </li>
            <li class="">
                <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10590623.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10590623.html","ab":"new"}'>
                    <img src="https://img-blog.csdnimg.cn/2021082518443179.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                    <span class="title oneline">
                        <span class="text">SQL入门到精通教程系列</span>
                    </span>
                    <span class="count float-right">6篇</span>
                </a>
            </li>
        </ul>
    </div>
    <p class="text-center">
        <a class="flexible-btn" data-fbox="aside-archive"><img class="look-more" src="https://csdnimg.cn/release/blogv2/dist/pc/img/arrowDownBlack.png" alt=""></a>
    </p>
</div>
<div id="asideNewComments" class="aside-box">
    <h3 class="aside-title">最新评论</h3>
    <div class="aside-content">
        <ul class="newcomment-list">
            <li>
                <a class="title text-truncate" target="_blank" href="https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18346433" data-report-click='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18346433","ab":"new"}' data-report-view='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18346433","ab":"new"}'>❤️ 万字Python MySQL从入门到精通详细教程❤️ 再也不用担心学不会数据库了❤️</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/jianpengxuexikaifa" class="user-name" target="_blank">程序员漫话编程: </a>
                    <span class="code-comments">看了目录就被吸引了，总结的到位，太棒了，大佬666，欢迎回访。</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://chuanchuan.blog.csdn.net/article/details/120076709#comments_18344986" data-report-click='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120076709#comments_18344986","ab":"new"}' data-report-view='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120076709#comments_18344986","ab":"new"}'>❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）</a>
                <p class="comment ellipsis">
                    <a href="https://blog.csdn.net/m0_60695898" class="user-name" target="_blank">m0_60695898: </a>
                    <span class="code-comments">这还是基础的大哥 这你都开始不懂了怎么搞  我觉得川川这个绝对 YYDS</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342039" data-report-click='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342039","ab":"new"}' data-report-view='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342039","ab":"new"}'>❤️ 万字Python MySQL从入门到精通详细教程❤️ 再也不用担心学不会数据库了❤️</a>
                <p class="comment ellipsis">
                    <a href="https://chuanchuan.blog.csdn.net" class="user-name" target="_blank">川川菜鸟: </a>
                    <span class="code-comments"><img src="https://g.csdnimg.cn/static/face/emoji/015.png" alt='表情包' >月薪过万不是梦</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342038" data-report-click='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342038","ab":"new"}' data-report-view='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342038","ab":"new"}'>❤️ 万字Python MySQL从入门到精通详细教程❤️ 再也不用担心学不会数据库了❤️</a>
                <p class="comment ellipsis">
                    <a href="https://chuanchuan.blog.csdn.net" class="user-name" target="_blank">川川菜鸟: </a>
                    <span class="code-comments"><img src="https://g.csdnimg.cn/static/face/emoji/015.png" alt='表情包' >月薪过万不是梦</span>
                </p>
            </li>
            <li>
                <a class="title text-truncate" target="_blank" href="https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342036" data-report-click='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342036","ab":"new"}' data-report-view='{"mod":"popu_542","spm":"1001.2101.3001.4231","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936#comments_18342036","ab":"new"}'>❤️ 万字Python MySQL从入门到精通详细教程❤️ 再也不用担心学不会数据库了❤️</a>
                <p class="comment ellipsis">
                    <a href="https://chuanchuan.blog.csdn.net" class="user-name" target="_blank">川川菜鸟: </a>
                    <span class="code-comments"><img src="https://g.csdnimg.cn/static/face/emoji/015.png" alt='表情包' >月薪过万不是梦</span>
                </p>
            </li>
        </ul>
    </div>
</div>
<div id="asideNewNps" class="aside-box">
    <h3 class="aside-title">您愿意向朋友推荐“博客详情页”吗？</h3>
    <div class="aside-content">
        <ul class="newnps-list">
            <li class="newnps-item" data-type="强烈不推荐">
                <div class="newnps-img-box">
                    <img class="newnps-img active" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel1.png" alt="">
                    <img class="newnps-img default" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeelGrey1.png" alt="">
                </div>
                <div class="newnps-text">强烈不推荐</div>
            </li>
            <li class="newnps-item" data-type="不推荐">
                <div class="newnps-img-box">
                    <img class="newnps-img active" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel2.png" alt="">
                    <img class="newnps-img default" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeelGrey2.png" alt="">
                </div>
                <div class="newnps-text">不推荐</div>
            </li>
            <li class="newnps-item" data-type="一般般">
                <div class="newnps-img-box">
                    <img class="newnps-img active" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel3.png" alt="">
                    <img class="newnps-img default" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeelGrey3.png" alt="">
                </div>
                <div class="newnps-text">一般般</div>
            </li>
            <li class="newnps-item" data-type="推荐">
                <div class="newnps-img-box">
                    <img class="newnps-img active" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel4.png" alt="">
                    <img class="newnps-img default" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeelGrey4.png" alt="">
                </div>
                <div class="newnps-text">推荐</div>
            </li>
            <li class="newnps-item" data-type="强烈推荐">
                <div class="newnps-img-box">
                    <img class="newnps-img active" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeel5.png" alt="">
                    <img class="newnps-img default" src="https://csdnimg.cn/release/blogv2/dist/pc/img/npsFeelGrey5.png" alt="">
                </div>
                <div class="newnps-text">强烈推荐</div>
            </li>
        </ul>
        <div class="newnps-form-box">
        <div class="newnps-form">
            <input type="text" placeholder="请输入建议或反馈后点击提交" class="newnps-input">
            <span class="newnps-btn">提交</span>
        </div>
        </div>
    </div>
</div>
<div id="asideArchive" class="aside-box" style="display:block!important; width:300px;">
    <h3 class="aside-title">最新文章</h3>
    <div class="aside-content">
        <ul class="inf_list clearfix">
            <li class="clearfix">
            <a href="https://chuanchuan.blog.csdn.net/article/details/120298936" target="_blank" data-report-click='{"mod":"popu_382","spm":"1001.2101.3001.4136","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936","ab":"new"}' data-report-view='{"mod":"popu_382","dest":"https://chuanchuan.blog.csdn.net/article/details/120298936","ab":"new"}'>❤️ 万字Python MySQL从入门到精通详细教程❤️ 再也不用担心学不会数据库了❤️</a>
            </li>
            <li class="clearfix">
            <a href="https://chuanchuan.blog.csdn.net/article/details/120298261" target="_blank" data-report-click='{"mod":"popu_382","spm":"1001.2101.3001.4136","dest":"https://chuanchuan.blog.csdn.net/article/details/120298261","ab":"new"}' data-report-view='{"mod":"popu_382","dest":"https://chuanchuan.blog.csdn.net/article/details/120298261","ab":"new"}'>Python MySQL合并</a>
            </li>
            <li class="clearfix">
            <a href="https://chuanchuan.blog.csdn.net/article/details/120298032" target="_blank" data-report-click='{"mod":"popu_382","spm":"1001.2101.3001.4136","dest":"https://chuanchuan.blog.csdn.net/article/details/120298032","ab":"new"}' data-report-view='{"mod":"popu_382","dest":"https://chuanchuan.blog.csdn.net/article/details/120298032","ab":"new"}'>Python MySQL限制</a>
            </li>
        </ul>
        <div class="archive-bar"></div>
        <div class="archive-box">
                <div class="archive-title">2021</div> 
                <div class="archive-content">
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/09" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/09"}'>
                        <span class="time">09月</span>
                        <span class="count">35篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/08" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/08"}'>
                        <span class="time">08月</span>
                        <span class="count">131篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/07" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/07"}'>
                        <span class="time">07月</span>
                        <span class="count">79篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/06" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/06"}'>
                        <span class="time">06月</span>
                        <span class="count">16篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/05" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/05"}'>
                        <span class="time">05月</span>
                        <span class="count">16篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/04" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/04"}'>
                        <span class="time">04月</span>
                        <span class="count">24篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/03" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/03"}'>
                        <span class="time">03月</span>
                        <span class="count">6篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/02" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/02"}'>
                        <span class="time">02月</span>
                        <span class="count">12篇</span>
                        </a>
                    </div>
                    <div class="archive-item">
                        <a href="https://chuanchuan.blog.csdn.net/article/month/2021/01" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":"https://chuanchuan.blog.csdn.net/article/month/2021/01"}'>
                        <span class="time">01月</span>
                        <span class="count">25篇</span>
                        </a>
                    </div>
                </div>
                <div class="archive-list-item"><a href="https://chuanchuan.blog.csdn.net/article/month/2020/12" target="_blank" data-report-click='{"mod":"popu_538","spm":"1001.2101.3001.4138","ab":"new","dest":""}'><span class="year">2020年</span><span class="num">65篇</span></a></div>
        </div>
    </div>
</div>
	<div id="footerRightAds" class="isShowFooterAds">
		<div class="aside-box">
			<div id="kp_box_57" data-pid="57"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- PC-博客详情页-矩形-左下视窗（自适应） -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-1076724771190722"
     data-ad-slot="1894159733"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=57&a=707&c=0&k=&spm=1001.2101.3001.5001&d=1&t=3&u=365fdf1c7e5e49a38af1d07c1422aee9" style="display: block;width: 0px;height: 0px;"></div>
		</div>
	</div>
    <!-- 详情页显示目录 -->
<!--文章目录-->
<div id="asidedirectory" class="aside-box">
    <div class='groupfile' id="directory">
        <h3 class="aside-title">目录</h3>
        <div class="align-items-stretch group_item">
            <div class="pos-box">
            <div class="scroll-box">
                <div class="toc-box"></div>
            </div>
            </div>
        </div>
    </div>
</div>
</aside>
<script>
	$("a.flexible-btn").click(function(){
		$(this).parents('div.aside-box').removeClass('flexible-box');
		$(this).parents("p.text-center").remove();
	})
</script>
<script type="text/javascript"  src="https://g.csdnimg.cn/user-tooltip/2.5/user-tooltip.js"></script>
<script type="text/javascript"  src="https://g.csdnimg.cn/user-medal/1.0.7/user-medal.js"></script>    </div>
<div class="recommend-right  align-items-stretch clearfix" id="rightAside" data-type="recommend">
    <aside class="recommend-right_aside">
        <div id="recommend-right" >
                        <div class='flex-column aside-box groupfile' id="groupfile">
                <div class="groupfile-div">
                <h3 class="aside-title">目录</h3>
                <div class="align-items-stretch group_item">
                    <div class="pos-box">
                        <div class="scroll-box">
                            <div class="toc-box"></div>
                        </div>
                    </div>
                </div>
                </div>
            </div>
                <div id="recommendAdBox">
                    <div id="kp_box_479" data-pid="479"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- PC-博客详情页-右侧视窗（自适应） -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-1076724771190722"
     data-ad-slot="3484057394"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=479&a=3267&c=0&k=&spm=1001.2101.3001.4834&d=1&t=3&u=223a201a2bcf4d17964431ba10c0226e" style="display: block;width: 0px;height: 0px;"></div>
                </div>
            <div class='aside-box kind_person d-flex flex-column'>
                    <h3 class="aside-title">分类专栏</h3>
                    <div class="align-items-stretch kindof_item" id="kind_person_column">
                        <div class="aside-content">
                            <ul>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11242184.html" data-report-click='{"mod":"popu_826","spm":"1001.2101.3001.4230","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11242184.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20210909221847641.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">数学建模小白到精通系列</span>
                                            <img class="tip" src="https://csdnimg.cn/release/blogv2/dist/pc/img/payMoney.png" alt="">
                                        </span>
                                        <span class="count float-right">51篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11313211.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11313211.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20210825184045537.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">python全栈基础教程系列</span>
                                        </span>
                                        <span class="count float-right">28篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11324293.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11324293.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">matlab语音信号处理</span>
                                        </span>
                                        <span class="count float-right">4篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11320323.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11320323.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">零基础进军人工智能教程</span>
                                        </span>
                                        <span class="count float-right">10篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11329089.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11329089.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20190918135101160.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">C++从零到精通教程系列</span>
                                        </span>
                                        <span class="count float-right">3篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_11310522.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_11310522.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20190927151117521.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">c语言数据结构教程系列</span>
                                        </span>
                                        <span class="count float-right">2篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10912318.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10912318.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20210825184642604.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">qq机器人小白教程系列</span>
                                        </span>
                                        <span class="count float-right">27篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10532683.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10532683.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/20190927151043371.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">python案例和工具</span>
                                        </span>
                                        <span class="count float-right">64篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10425986.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10425986.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/2021082518423471.jpg?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">瞎写点爬虫教程案例</span>
                                        </span>
                                        <span class="count float-right">23篇</span>
                                    </a>
                                </li>
                                <li class="">
                                    <a class="clearfix" target="_blank" href="https://blog.csdn.net/weixin_46211269/category_10590623.html" data-report-click='{"mod":"popu_537","spm":"1001.2101.3001.4137","strategy":"pc付费专栏左侧入口","dest":"https://blog.csdn.net/weixin_46211269/category_10590623.html","ab":"new"}'>
                                        <img src="https://img-blog.csdnimg.cn/2021082518443179.png?x-oss-process=image/resize,m_fixed,h_64,w_64" alt="" onerror="this.src='https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64'">
                                        <span class="title oneline">
                                            <span class="text">SQL入门到精通教程系列</span>
                                        </span>
                                        <span class="count float-right">6篇</span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
            </div>
        </div>
    </aside>
</div>

</div>
<div class="mask-dark"></div>
<script type="text/javascript">
    var timert = setInterval(function(){
      sideToolbar = $(".csdn-side-toolbar");
      if (sideToolbar.length > 0) {
        sideToolbar.css('cssText','bottom:64px !important;')
        clearInterval(timert);
      }
    }, 200);
</script>
<script>
    var articleId = 120076709;
    var commentscount = 208;
    var curentUrl = "https://blog.csdn.net/weixin_46211269/article/details/120076709";
    var myUrl = "https://my.csdn.net/";
    var highlight = ["python","❤","零到","大佬","️","零教","精通","收藏","pycharm","字","变","建议","爆肝","十二万","教程"];//高亮数组
    var isRecommendModule = true;
    var isBaiduPre = true;
    var baiduCount = 2;
    var share_card_url = "https://blog.csdn.net/weixin_46211269/article/shareArticleCardPage?article_id=120076709"
	var articleType = 1;
    var baiduKey = "❤️爆肝十二万字《python从零到精通教程》，从零教你变大佬❤️（建议收藏）";
    var userNewReport = false;
    var needInsertBaidu = true;
    var recommendRegularDomainArr = ["blog.csdn.net/.+/article/details/","download.csdn.net/download/","edu.csdn.net/course/detail/","ask.csdn.net/questions/","bbs.csdn.net/topics/","www.csdn.net/gather_.+/"]
    var codeStyle = "tomorrow-night";
    var baiduSearchType = "title";
    var canRead = true;
    var blogMoveHomeArticle = false;
    var showPcWindowAd = false;
    var showSearchText = "";
    var linkPage = true;
    var articleSource = 1;
    var articleReport = '{"pid": "blog", "spm":"1001.2101"}';
    var isShowToQuestion = false;
    var baiduSearchChannel = 'pc_relevant'
    var baiduSearchIdentification = '.no_search_link'
    var initRewardObject = {
        giver: currentUserName,
        anchor: username,
        articleId: articleId,
        sign: ''
    }
</script>
<script src="https://csdnimg.cn/public/sandalstrap/1.4/js/sandalstrap.min.js"></script>
<div class="skin-boxshadow"></div>
<div class="directory-boxshadow"></div>
<div class="pay-code">
    <div class="pay-money">实付<span class="pay-money-span" data-nowprice='' data-oldprice=''>元</span></div>
    <div class="content-blance"><a class="blance-bt" href="javascript:;">使用余额支付</a></div>
    <div class="content-code">
    <div id="payCode" data-id="">
            <div class="renovate">
                <img src="https://csdnimg.cn/release/blogv2/dist/pc/img/pay-time-out.png">
                <span>点击重新获取</span>
            </div>
        </div>
        <div class="pay-style"><span><img src="https://csdnimg.cn/release/blogv2/dist/pc/img/weixin.png"></span><span><img src="https://csdnimg.cn/release/blogv2/dist/pc/img/zhifubao.png"></span><span><img src="https://csdnimg.cn/release/blogv2/dist/pc/img/jingdong.png"></span><span class="text">扫码支付</span></div>
    </div>
    <div class="bt-close"><svg t="1567152543821" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10924" xmlns:xlink="http://www.w3.org/1999/xlink" width="12" height="12"><defs><style type="text/css"></style></defs><path d="M512 438.378667L806.506667 143.893333a52.032 52.032 0 1 1 73.6 73.621334L585.621333 512l294.485334 294.485333a52.074667 52.074667 0 0 1-73.6 73.642667L512 585.621333 217.514667 880.128a52.053333 52.053333 0 1 1-73.621334-73.642667L438.378667 512 143.893333 217.514667a52.053333 52.053333 0 1 1 73.621334-73.621334L512 438.378667z" fill="" p-id="10925"></path></svg></div>
    <!-- <p style="margin-top: 8px;font-size: 14px;" class="text-center">支付成功即可阅读</p> -->
    <div class="pay-balance">
    <input type="radio" class="pay-code-radio" data-type="details"> 
    <span class="span">钱包余额</span>
    <span class="balance" style="color:#FC5531;font-size:14px;">0</span>  
    <div class="pay-code-tile">
        <img src="https://csdnimg.cn/release/blogv2/dist/pc/img/pay-help.png" alt="">
        <div class="pay-code-content">
            <div class="span">
                <p class="title">抵扣说明：</p>
                <p> 1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。<br> 2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。</p>
            </div>
        </div>
    </div>
    </div>
    <a class="pay-balance-con" href="https://i.csdn.net/#/wallet/balance/recharge" target="_blank"><img src="https://csdnimg.cn/release/blogv2/dist/pc/img/recharge.png" alt=""><span  >余额充值</span></a>
</div>
<div style="display:none;">
	<img src="" onerror='setTimeout(function(){if(!/(csdn.net|iteye.com|baiducontent.com|googleusercontent.com|360webcache.com|sogoucdn.com|bingj.com|baidu.com)$/.test(window.location.hostname)){window.location.href="\x68\x74\x74\x70\x73\x3a\x2f\x2f\x77\x77\x77\x2e\x63\x73\x64\x6e\x2e\x6e\x65\x74"}},3000);'>
</div>
</body>
<script src="https://csdnimg.cn/release/blogv2/dist/components/js/pc_wap_highlight-db1e81323a.min.js" type="text/javascript"></script>
<script src="https://csdnimg.cn/release/blogv2/dist/components/js/pc_wap_common-6a9acd4c62.min.js" type="text/javascript"></script>
<script src="https://csdnimg.cn/release/blogv2/dist/components/js/edit_copy_code-1320dfe85c.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://csdnimg.cn/release/blog_editor_html/release1.6.12/ckeditor/plugins/codesnippet/lib/highlight/styles/tomorrow-night.css">
<script>
 // 全局声明
 if (window.csdn === undefined) {
      window.csdn = {};
    }
    window.csdn.sideToolbar = {
        options: {
            report:{
                isShow: true,
            },
            qr: {
                isShow: false,
            },
            guide: {
                isShow: true
            }
        }
    }
    $(function(){
        $(document).on('click',"a.option-box[data-type='report']",function() {
            window.csdn.userLogin.loadAjax(function(res){
                if(userNewReport){
                    showReportNew(false,articleTitles);
                }else{
                    showReport(false,articleTitles);
                }
            })
        });
    })
</script>
    <script src="https://g.csdnimg.cn/baidu-search/1.0.9/baidu-search.js"  type="text/javascript"></script>
<script src="https://csdnimg.cn/release/download/old_static/js/qrcode.js"></script>
<script src="https://g.csdnimg.cn/lib/qrcode/1.0.0/qrcode.min.js"></script>
<script src="https://g.csdnimg.cn/user-ordercart/2.0.6/user-ordercart.js" type="text/javascript"></script>
<script src="https://g.csdnimg.cn/user-ordertip/4.1.3/user-ordertip.js" type="text/javascript" ></script>
<script src="https://csdnimg.cn/release/blogv2/dist/pc/js/common-24fa4dcb20.min.js" type="text/javascript"></script>
<script src="https://csdnimg.cn/release/blogv2/dist/pc/js/detail-44f0825236.min.js" type="text/javascript"></script>
<script src="https://csdnimg.cn/release/blogv2/dist/pc/js/column-8eca907613.min.js" type="text/javascript"></script>
<script src="https://g.csdnimg.cn/side-toolbar/3.0/side-toolbar.js" type="text/javascript"></script>
<script>
 window.csdn.voteBox = window.csdn.voteBox ? window.csdn.voteBox : {};
 window.csdn.voteBox.voteBoxParams = {
    inited: function () {
      var voteBox = document.getElementById('blogVoteBox'); // 位置dom元素
      window.csdn.voteBox.show({
        id: 1244828, // voteId
	    isdark: true, // 是否黑皮肤
        voteusername: "weixin_46211269",
        posDom: voteBox, // 插入位置 selectorString || 位置dom元素
        needLogin: () => { // 登录弹窗
            window.csdn.loginBox.show();
        },
        voteFaild: (data) => { // 投票失败
            showToast({
                text: '投票失败，请重新操作!',
                bottom: '10%', //toast距离页面底部的距离
                zindex: 9000, //为了防止被其他控件遮盖，z-index默认为2
                speed: 500, //toast的显示速度
                time: 1500//toast显示多久以后消失
            });
        }
      });
    }
  }
</script>
<script src="https://g.csdnimg.cn/vote-box/1.1.2/vote-box.js" type="text/javascript"></script>
<script>
window.csdn.extensionBox = window.csdn.extensionBox ? window.csdn.extensionBox : {};
window.csdn.extensionBox.extensionBoxParams = {
    inited: function () {
    var extensionBox = document.getElementById('blogExtensionBox'); // 位置dom元素
    window.csdn.extensionBox.show({
        isdark:true, // 是否黑皮肤
        voteusername: "weixin_46211269",
        posDom: extensionBox, // 插入位置 selectorString || 位置dom元素
        codyFn:()=>{
        //复制成功回调函数
            showToast({
                text: '复制成功!',
                bottom: '10%', //toast距离页面底部的距离
                zindex: 9000, //为了防止被其他控件遮盖，z-index默认为2
                speed: 500, //toast的显示速度
                time: 1500//toast显示多久以后消失
            });
        }
    });
    }
}
</script>
<script src="https://g.csdnimg.cn/extension-box/1.1.3/extension-box.js" type="text/javascript"></script>
<script src="https://g.csdnimg.cn/copyright/1.0.4/copyright.js" type="text/javascript"></script>
<script>
    $(".MathJax").remove();
    if ($('div.markdown_views pre.prettyprint code.hljs').length > 0) {
        $('div.markdown_views')[0].className = 'markdown_views';
    }
</script>
<script type="text/javascript" src="https://csdnimg.cn/release/blog_mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
            "HTML-CSS": {
                    linebreaks: { automatic: true, width: "94%container" },
                    imageFont: null
            },
            tex2jax: {
                preview: "none",
                ignoreClass:"title-article"
            },
            mml2jax: {
                preview: 'none'
            }
    });
</script>
<script type="text/javascript" crossorigin src="https://g.csdnimg.cn/login-box/1.1.7/login-box.js"></script></html>
